Partial merge of the condrv_restructure branch, including:
[reactos.git] / reactos / base / applications / network / net / cmdStop.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE:
5 * PURPOSE:
6 *
7 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
8 */
9
10 #include "net.h"
11
12 INT cmdStop(INT argc, WCHAR **argv)
13 {
14 SC_HANDLE hManager = NULL;
15 SC_HANDLE hService = NULL;
16 SERVICE_STATUS ServiceStatus;
17 DWORD dwError = ERROR_SUCCESS;
18 INT nError = 0;
19 INT i;
20
21 if (argc != 3)
22 {
23 PrintResourceString(IDS_STOP_SYNTAX);
24 return 1;
25 }
26
27 for (i = 2; i < argc; i++)
28 {
29 if (_wcsicmp(argv[i], L"/help") == 0)
30 {
31 PrintResourceString(IDS_STOP_HELP);
32 return 1;
33 }
34 }
35
36 hManager = OpenSCManagerW(NULL,
37 SERVICES_ACTIVE_DATABASE,
38 SC_MANAGER_ENUMERATE_SERVICE);
39 if (hManager == NULL)
40 {
41 dwError = GetLastError();
42 nError = 1;
43 goto done;
44 }
45
46 hService = OpenServiceW(hManager,
47 argv[2],
48 SERVICE_STOP);
49 if (hService == NULL)
50 {
51 dwError = GetLastError();
52 nError = 1;
53 goto done;
54 }
55
56 if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
57 {
58 dwError = GetLastError();
59 nError = 1;
60 goto done;
61 }
62
63 done:
64 if (hService != NULL)
65 CloseServiceHandle(hService);
66
67 if (hManager != NULL)
68 CloseServiceHandle(hManager);
69
70 if (dwError != ERROR_SUCCESS)
71 {
72 /* FIXME: Print proper error message */
73 printf("Error: %lu\n", dwError);
74 }
75
76 return nError;
77 }