[NTOSKRNL]
[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:
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
20 if (argc != 3)
21 {
22 /* FIXME: Print usage message! */
23 printf("Usage: NET STOP <Service name>\n");
24 return 1;
25 }
26
27 hManager = OpenSCManagerW(NULL,
28 SERVICES_ACTIVE_DATABASE,
29 SC_MANAGER_ENUMERATE_SERVICE);
30 if (hManager == NULL)
31 {
32 dwError = GetLastError();
33 nError = 1;
34 goto done;
35 }
36
37 hService = OpenServiceW(hManager,
38 argv[2],
39 SERVICE_STOP);
40 if (hService == NULL)
41 {
42 dwError = GetLastError();
43 nError = 1;
44 goto done;
45 }
46
47 if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
48 {
49 dwError = GetLastError();
50 nError = 1;
51 goto done;
52 }
53
54 done:
55 if (hService != NULL)
56 CloseServiceHandle(hService);
57
58 if (hManager != NULL)
59 CloseServiceHandle(hManager);
60
61 if (dwError != ERROR_SUCCESS)
62 {
63 /* FIXME: Print proper error message */
64 printf("Error: %lu\n", dwError);
65 }
66
67 return nError;
68 }