[NET] CORE-6413
[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
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 printf("1\n");
33 dwError = GetLastError();
34 nError = 1;
35 goto done;
36 }
37
38 hService = OpenServiceW(hManager,
39 argv[2],
40 SERVICE_STOP);
41 if (hService == NULL)
42 {
43 printf("2\n");
44 dwError = GetLastError();
45 nError = 1;
46 goto done;
47 }
48
49 if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
50 {
51 printf("3\n");
52 dwError = GetLastError();
53 nError = 1;
54 goto done;
55 }
56
57 done:
58 if (hService != NULL)
59 CloseServiceHandle(hService);
60
61 if (hManager != NULL)
62 CloseServiceHandle(hManager);
63
64 if (dwError != ERROR_SUCCESS)
65 {
66 /* FIXME: Print proper error message */
67 printf("Error: %lu\n", dwError);
68 }
69
70 return nError;
71 }
72
73