ReactOS  0.4.12-dev-57-g7050ac4
control.c File Reference
#include "sc.h"
Include dependency graph for control.c:

Go to the source code of this file.

Functions

BOOL Control (DWORD Control, LPCTSTR ServiceName, LPCTSTR *Args, INT ArgCount)
 

Function Documentation

◆ Control()

BOOL Control ( DWORD  Control,
LPCTSTR  ServiceName,
LPCTSTR Args,
INT  ArgCount 
)

Definition at line 13 of file control.c.

17 {
18  SC_HANDLE hSCManager = NULL;
19  SC_HANDLE hService = NULL;
21  DWORD dwDesiredAccess = 0;
22  BOOL bResult = TRUE;
23  SERVICE_STATUS_PROCESS StatusEx;
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 
68  hSCManager = OpenSCManager(NULL,
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 
107 done:
108  if (!bResult)
109  ReportLastError();
110 
111  if (hService)
112  CloseServiceHandle(hService);
113 
114  if (hSCManager)
115  CloseServiceHandle(hSCManager);
116 
117  return bResult;
118 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_INTERROGATE
Definition: winsvc.h:60
int32_t INT
Definition: typedefs.h:56
#define OpenService
Definition: winsvc.h:576
#define SERVICE_CONTROL_PARAMCHANGE
Definition: winsvc.h:41
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
BOOL Control(DWORD Control, LPCTSTR ServiceName, LPCTSTR *Args, INT ArgCount)
Definition: control.c:13
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
char ** Args
Definition: acdebug.h:342
#define OpenSCManager
Definition: winsvc.h:575
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
LPTSTR ServiceName
Definition: ServiceMain.c:15
#define SERVICE_USER_DEFINED_CONTROL
Definition: winsvc.h:61
#define CopyMemory
Definition: winbase.h:1633
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_NETBINDADD
Definition: winsvc.h:42
SC_HANDLE hSCManager
Definition: sc.c:12
Status
Definition: gdiplustypes.h:24
VOID ReportLastError(VOID)
Definition: sc.c:15
#define SERVICE_STOP
Definition: winsvc.h:58
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:618
#define SERVICE_CONTROL_NETBINDENABLE
Definition: winsvc.h:44
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_CONTROL_NETBINDDISABLE
Definition: winsvc.h:45
#define SERVICE_CONTROL_NETBINDREMOVE
Definition: winsvc.h:43
#define SERVICE_PAUSE_CONTINUE
Definition: winsvc.h:59
VOID PrintService(LPCTSTR lpServiceName, LPCTSTR lpDisplayName, LPSERVICE_STATUS_PROCESS pStatus, BOOL bExtended)
Definition: print.c:13