ReactOS 0.4.16-dev-136-g52192f1
control.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/sc/control.c
5 * PURPOSE: Stops, pauses and resumes a service
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
7 *
8 */
9
10#include "sc.h"
11
12BOOL
16 INT ArgCount)
17{
18 SC_HANDLE hSCManager = NULL;
19 SC_HANDLE hService = NULL;
21 DWORD dwDesiredAccess = 0;
22 BOOL bResult = TRUE;
24
25#ifdef SCDBG
26 LPCTSTR *TmpArgs = Args;
27 INT TmpCnt = ArgCount;
28 _tprintf(_T("service to control - %s\n"), ServiceName);
29 _tprintf(_T("command - %lu\n"), Control);
30 _tprintf(_T("Arguments:\n"));
31 while (TmpCnt)
32 {
33 _tprintf(_T(" %s\n"), *TmpArgs);
34 TmpArgs++;
35 TmpCnt--;
36 }
37 _tprintf(_T("\n"));
38#endif /* SCDBG */
39
40 switch (Control)
41 {
43 dwDesiredAccess = SERVICE_STOP;
44 break;
45
53 dwDesiredAccess = SERVICE_PAUSE_CONTINUE;
54 break;
55
57 dwDesiredAccess = SERVICE_INTERROGATE;
58 break;
59
60 default:
61 if (Control >= 128 && Control <= 255)
62 dwDesiredAccess = SERVICE_USER_DEFINED_CONTROL;
63 else
64 dwDesiredAccess = 0;
65 break;
66 }
67
69 NULL,
71 if (hSCManager == NULL)
72 {
73 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
74 bResult = FALSE;
75 goto done;
76 }
77
78 hService = OpenService(hSCManager,
80 dwDesiredAccess);
81 if (hService == NULL)
82 {
83 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
84 bResult = FALSE;
85 goto done;
86 }
87
88 if (!ControlService(hService,
89 Control,
90 &Status))
91 {
92 _tprintf(_T("[SC] ControlService FAILED %lu:\n\n"), GetLastError());
93 bResult = FALSE;
94 goto done;
95 }
96
97 /* FIXME: lazy hack ;) */
98 CopyMemory(&StatusEx, &Status, sizeof(Status));
99 StatusEx.dwProcessId = 0;
100 StatusEx.dwServiceFlags = 0;
101
103 NULL,
104 &StatusEx,
105 FALSE);
106
107done:
108 if (!bResult)
110
111 if (hService)
112 CloseServiceHandle(hService);
113
114 if (hSCManager)
116
117 return bResult;
118}
char ** Args
Definition: acdebug.h:353
VOID PrintService(LPCTSTR lpServiceName, LPCTSTR lpDisplayName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended)
Definition: print.c:13
static WCHAR ServiceName[]
Definition: browser.c:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
#define _tprintf
Definition: tchar.h:506
DWORD ReportLastError(void)
Definition: loadlib.c:67
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
_In_ WDF_WMI_PROVIDER_CONTROL Control
Definition: wdfwmi.h:166
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1710
#define SERVICE_CONTROL_PARAMCHANGE
Definition: winsvc.h:41
#define SERVICE_CONTROL_NETBINDREMOVE
Definition: winsvc.h:43
#define SERVICE_CONTROL_NETBINDADD
Definition: winsvc.h:42
#define OpenSCManager
Definition: winsvc.h:575
#define SERVICE_USER_DEFINED_CONTROL
Definition: winsvc.h:61
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define SERVICE_CONTROL_NETBINDDISABLE
Definition: winsvc.h:45
#define SERVICE_PAUSE_CONTINUE
Definition: winsvc.h:59
#define SERVICE_CONTROL_NETBINDENABLE
Definition: winsvc.h:44
#define SERVICE_INTERROGATE
Definition: winsvc.h:60
#define SERVICE_STOP
Definition: winsvc.h:58
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define OpenService
Definition: winsvc.h:576
const CHAR * LPCTSTR
Definition: xmlstorage.h:193