[NET] Implement the group command
[reactos.git] / base / applications / network / net / cmdStop.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/cmdStop.c
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 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
24 ConResPuts(StdOut, IDS_STOP_SYNTAX);
25 return 1;
26 }
27
28 for (i = 2; i < argc; i++)
29 {
30 if (_wcsicmp(argv[i], L"/help") == 0)
31 {
32 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
33 ConResPuts(StdOut, IDS_STOP_SYNTAX);
34 ConResPuts(StdOut, IDS_STOP_HELP_1);
35 ConResPuts(StdOut, IDS_STOP_HELP_2);
36 ConResPuts(StdOut, IDS_STOP_HELP_3);
37 return 1;
38 }
39 }
40
41 hManager = OpenSCManagerW(NULL,
42 SERVICES_ACTIVE_DATABASE,
43 SC_MANAGER_ENUMERATE_SERVICE);
44 if (hManager == NULL)
45 {
46 dwError = GetLastError();
47 nError = 1;
48 goto done;
49 }
50
51 hService = OpenServiceW(hManager,
52 argv[2],
53 SERVICE_STOP);
54 if (hService == NULL)
55 {
56 dwError = GetLastError();
57 nError = 1;
58 goto done;
59 }
60
61 if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
62 {
63 dwError = GetLastError();
64 nError = 1;
65 goto done;
66 }
67
68 done:
69 if (hService != NULL)
70 CloseServiceHandle(hService);
71
72 if (hManager != NULL)
73 CloseServiceHandle(hManager);
74
75 if (dwError != ERROR_SUCCESS)
76 {
77 /* FIXME: Print proper error message */
78 ConPrintf(StdErr, L"Error: %lu\n", dwError);
79 }
80
81 return nError;
82 }