e9965d7e37e4cb1c549db1594db92c4c7f86352c
[reactos.git] / reactos / subsys / system / sc / control.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS SC utility
4 * FILE: subsys/system/sc/control.c
5 * PURPOSE: control ReactOS services
6 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
7 * REVISIONS:
8 * Ged Murphy 20/10/05 Created
9 *
10 */
11
12 #include "sc.h"
13
14 /*
15 * handles the following commands:
16 * control, continue, interrogate, pause, stop
17 */
18
19 BOOL Control(DWORD Control, LPCTSTR ServiceName, LPCTSTR *Args)
20 {
21 SC_HANDLE hSc;
22 SERVICE_STATUS Status;
23
24 /* testing */
25 _tprintf(_T("service to control - %s\n\n"), ServiceName);
26 _tprintf(_T("command - %lu\n\n"), Control);
27 _tprintf(_T("Arguments :\n"));
28 while (*Args)
29 {
30 printf("%s\n", *Args);
31 Args++;
32 }
33
34
35 hSc = OpenService(hSCManager, ServiceName,
36 SERVICE_INTERROGATE | SERVICE_PAUSE_CONTINUE |
37 SERVICE_STOP | SERVICE_USER_DEFINED_CONTROL |
38 SERVICE_QUERY_STATUS);
39
40 if (hSc == NULL)
41 {
42 _tprintf(_T("openService failed\n"));
43 ReportLastError();
44 return FALSE;
45 }
46
47 if (! ControlService(hSc, Control, &Status))
48 {
49 _tprintf(_T("controlService failed\n"));
50 ReportLastError();
51 return FALSE;
52 }
53
54 CloseServiceHandle(hSc);
55
56 /* print the status information */
57
58 return TRUE;
59
60 }