Lars Martin Hambro <lars_martin4 AT hotmail DOT com>
[reactos.git] / base / applications / mscutils / servman / stop.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/stop.c
5 * PURPOSE: Stops running a service
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10 #include "precomp.h"
11
12 BOOL
13 DoStop(PMAIN_WND_INFO Info)
14 {
15 SC_HANDLE hSCManager = NULL;
16 SC_HANDLE hSc = NULL;
17 LPQUERY_SERVICE_CONFIG lpServiceConfig = NULL;
18 HWND hProgDlg;
19 DWORD BytesNeeded = 0;
20 BOOL ret = FALSE;
21
22 hSCManager = OpenSCManager(NULL,
23 NULL,
24 SC_MANAGER_ENUMERATE_SERVICE);
25 if (hSCManager == NULL)
26 {
27 GetError();
28 return FALSE;
29 }
30
31 hSc = OpenService(hSCManager,
32 Info->pCurrentService->lpServiceName,
33 SERVICE_QUERY_CONFIG);
34 if (hSc)
35 {
36 if (!QueryServiceConfig(hSc,
37 lpServiceConfig,
38 0,
39 &BytesNeeded))
40 {
41 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
42 {
43 lpServiceConfig = (LPQUERY_SERVICE_CONFIG)HeapAlloc(ProcessHeap,
44 0,
45 BytesNeeded);
46 if (lpServiceConfig == NULL)
47 goto cleanup;
48
49 if (QueryServiceConfig(hSc,
50 lpServiceConfig,
51 BytesNeeded,
52 &BytesNeeded))
53 {
54 #if 0
55 if (lpServiceConfig->lpDependencies)
56 {
57 TCHAR str[500];
58
59 _sntprintf(str, 499, _T("%s depends on this service, implement the dialog to allow closing of other services"),
60 lpServiceConfig->lpDependencies);
61 MessageBox(NULL, str, NULL, 0);
62
63 //FIXME: open 'stop other services' box
64 }
65 else
66 {
67 #endif
68 hProgDlg = CreateProgressDialog(Info->hMainWnd,
69 Info->pCurrentService->lpServiceName,
70 IDS_PROGRESS_INFO_STOP);
71 if (hProgDlg)
72 {
73 ret = Control(Info,
74 hProgDlg,
75 SERVICE_CONTROL_STOP);
76
77 DestroyWindow(hProgDlg);
78 }
79 //}
80
81 HeapFree(ProcessHeap,
82 0,
83 lpServiceConfig);
84
85 lpServiceConfig = NULL;
86 }
87 }
88 }
89 }
90
91 cleanup:
92 if (hSCManager != NULL)
93 CloseServiceHandle(hSCManager);
94 if (hSc != NULL)
95 CloseServiceHandle(hSc);
96
97 return ret;
98 }