ReactOS  0.4.13-dev-66-gc714b7f
sc.c File Reference
#include "sc.h"
Include dependency graph for sc.c:

Go to the source code of this file.

Functions

VOID ReportLastError (VOID)
 
static INT ScControl (LPCTSTR Server, LPCTSTR Command, LPCTSTR *ServiceArgs, DWORD ArgCount)
 
int _tmain (int argc, LPCTSTR argv[])
 

Variables

SC_HANDLE hSCManager
 

Function Documentation

◆ _tmain()

int _tmain ( int  argc,
LPCTSTR  argv[] 
)

Definition at line 335 of file sc.c.

336 {
337  LPCTSTR Server = NULL; // remote machine
338  LPCTSTR Command = NULL; // sc command
339  LPCTSTR *Args = NULL; // Any remaining args
340 
341  if (argc < 2)
342  {
343  MainUsage();
344  return -1;
345  }
346 
347  /* get server name */
348  if ((argv[1][0] == '\\') && (argv[1][1] == '\\'))
349  {
350  if (argc < 3)
351  {
352  MainUsage();
353  return -1;
354  }
355 
356  Server = argv[1];
357  Command = argv[2];
358  if (argc > 3)
359  Args = &argv[3];
360 
361  return ScControl(Server,
362  Command,
363  Args,
364  argc-3);
365  }
366  else
367  {
368  Command = argv[1];
369  if (argc > 2)
370  Args = &argv[2];
371 
372  return ScControl(Server,
373  Command,
374  Args,
375  argc-2);
376  }
377 }
static int argc
Definition: ServiceArgs.c:12
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
static INT ScControl(LPCTSTR Server, LPCTSTR Command, LPCTSTR *ServiceArgs, DWORD ArgCount)
Definition: sc.c:43
Definition: shell.h:41
static void Server(int port)
Definition: srltest.c:69
#define argv
Definition: mplay32.c:18
smooth NULL
Definition: ftsmooth.c:416
char ** Args
Definition: acdebug.h:343
VOID MainUsage(VOID)
Definition: usage.c:14

◆ ReportLastError()

VOID ReportLastError ( VOID  )

Definition at line 15 of file sc.c.

16 {
17  LPVOID lpMsgBuf;
18  DWORD RetVal;
19 
21  if (ErrorCode != ERROR_SUCCESS)
22  {
26  NULL,
27  ErrorCode,
28  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
29  (LPTSTR) &lpMsgBuf,
30  0,
31  NULL );
32 
33  if (RetVal != 0)
34  {
35  _tprintf(_T("%s"), (LPTSTR)lpMsgBuf);
36  LocalFree(lpMsgBuf);
37  }
38  }
39 }
#define _tprintf
Definition: tchar.h:506
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LANG_NEUTRAL
Definition: nls.h:22
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FormatMessage
Definition: winbase.h:3609
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define MAKELANGID(p, s)
Definition: nls.h:15

Referenced by Control(), Create(), Delete(), EnumDepend(), EnumServices(), GetDisplayName(), GetKeyName(), QueryConfig(), QueryDescription(), QueryFailure(), QueryService(), SdSet(), SdShow(), SetConfig(), SetDescription(), SetFailure(), and Start().

◆ ScControl()

static INT ScControl ( LPCTSTR  Server,
LPCTSTR  Command,
LPCTSTR ServiceArgs,
DWORD  ArgCount 
)
static

Definition at line 43 of file sc.c.

47 {
49 
50  if (Server)
51  {
52  _tprintf(_T("Remote service control is not yet implemented\n"));
53  return 2;
54  }
55 
56  if (!lstrcmpi(Command, _T("query")))
57  {
58  Query(ServiceArgs,
59  ArgCount,
60  FALSE);
61  }
62  else if (!lstrcmpi(Command, _T("queryex")))
63  {
64  Query(ServiceArgs,
65  ArgCount,
66  TRUE);
67  }
68  else if (!lstrcmpi(Command, _T("start")))
69  {
70  if (ArgCount > 0)
71  {
72  ServiceName = *ServiceArgs++;
73  ArgCount--;
74 
76  ServiceArgs,
77  ArgCount);
78  }
79  else
80  StartUsage();
81  }
82  else if (!lstrcmpi(Command, _T("pause")))
83  {
84  if (ArgCount > 0)
85  {
86  ServiceName = *ServiceArgs++;
87  ArgCount--;
88 
91  ServiceArgs,
92  ArgCount);
93  }
94  else
95  PauseUsage();
96  }
97  else if (!lstrcmpi(Command, _T("interrogate")))
98  {
99  if (ArgCount > 0)
100  {
101  ServiceName = *ServiceArgs++;
102  ArgCount--;
103 
105  ServiceName,
106  ServiceArgs,
107  ArgCount);
108  }
109  else
111  }
112  else if (!lstrcmpi(Command, _T("stop")))
113  {
114  if (ArgCount > 0)
115  {
116  ServiceName = *ServiceArgs++;
117  ArgCount--;
118 
120  ServiceName,
121  ServiceArgs,
122  ArgCount);
123  }
124  else
125  StopUsage();
126  }
127  else if (!lstrcmpi(Command, _T("continue")))
128  {
129  if (ArgCount > 0)
130  {
131  ServiceName = *ServiceArgs++;
132  ArgCount--;
133 
135  ServiceName,
136  ServiceArgs,
137  ArgCount);
138  }
139  else
140  ContinueUsage();
141  }
142  else if (!lstrcmpi(Command, _T("delete")))
143  {
144  if (ArgCount > 0)
145  {
146  ServiceName = *ServiceArgs++;
147  ArgCount--;
148 
150  }
151  else
152  DeleteUsage();
153  }
154  else if (!lstrcmpi(Command, _T("create")))
155  {
156  Create(ServiceArgs, ArgCount);
157  }
158  else if (!lstrcmpi(Command, _T("control")))
159  {
160  INT ControlCode = 0;
161 
162  if (ArgCount > 1)
163  {
164  ServiceName = *ServiceArgs++;
165  ArgCount--;
166 
167  if (!lstrcmpi(ServiceArgs[0], _T("paramchange")))
169  else if (!lstrcmpi(ServiceArgs[0], _T("netbindadd")))
171  else if (!lstrcmpi(ServiceArgs[0], _T("netbindremove")))
173  else if (!lstrcmpi(ServiceArgs[0], _T("netbindenable")))
175  else if (!lstrcmpi(ServiceArgs[0], _T("netbinddisable")))
177  else
178  {
179  ControlCode = _ttoi(ServiceArgs[0]);
180  if ((ControlCode < 128) || (ControlCode > 255))
181  ControlCode = 0;
182  }
183 
184  ServiceArgs++;
185  ArgCount--;
186 
187  if (ControlCode != 0)
189  ServiceName,
190  ServiceArgs,
191  ArgCount);
192  else
193  ControlUsage();
194  }
195  else
196  ControlUsage();
197  }
198  else if (!lstrcmpi(Command, _T("sdshow")))
199  {
200  if (ArgCount > 0)
201  {
202  ServiceName = *ServiceArgs++;
203  ArgCount--;
204 
206  }
207  else
208  SdShowUsage();
209  }
210  else if (!lstrcmpi(Command, _T("sdset")))
211  {
213 
214  if (ArgCount > 1)
215  {
216  ServiceName = *ServiceArgs++;
217  ArgCount--;
218 
219  SecurityDescriptor = *ServiceArgs++;
220  ArgCount--;
221 
223  }
224  else
225  SdSetUsage();
226  }
227  else if (!lstrcmpi(Command, _T("qc")))
228  {
229  if (ArgCount > 0)
230  {
231  ServiceName = *ServiceArgs++;
232  ArgCount--;
233 
235  }
236  else
238  }
239  else if (!lstrcmpi(Command, _T("qdescription")))
240  {
241  if (ArgCount > 0)
242  {
243  ServiceName = *ServiceArgs++;
244  ArgCount--;
245 
247  }
248  else
250  }
251  else if (!lstrcmpi(Command, _T("qfailure")))
252  {
253  if (ArgCount > 0)
254  {
255  ServiceName = *ServiceArgs++;
256  ArgCount--;
257 
259  }
260  else
262  }
263  else if (!lstrcmpi(Command, _T("description")))
264  {
266 
267  if (ArgCount > 0)
268  {
269  ServiceName = *ServiceArgs++;
270  ArgCount--;
271 
272  if (ArgCount > 0)
273  {
274  Description = *ServiceArgs++;
275  ArgCount--;
276  }
277 
279  }
280  else
282  }
283  else if (!lstrcmpi(Command, _T("config")))
284  {
285  SetConfig(ServiceArgs, ArgCount);
286  }
287  else if (!lstrcmpi(Command, _T("failure")))
288  {
289  SetFailure(ServiceArgs, ArgCount);
290  }
291  else if (!lstrcmpi(Command, _T("GetDisplayName")))
292  {
293  if (ArgCount > 0)
294  {
295  ServiceName = *ServiceArgs++;
296  ArgCount--;
297 
299  }
300  else
302  }
303  else if (!lstrcmpi(Command, _T("GetKeyName")))
304  {
305  if (ArgCount > 0)
306  {
307  ServiceName = *ServiceArgs++;
308  ArgCount--;
309 
311  }
312  else
313  GetKeyNameUsage();
314  }
315  else if (!lstrcmpi(Command, _T("EnumDepend")))
316  {
317  if (ArgCount > 0)
318  {
319  ServiceName = *ServiceArgs++;
320  ArgCount--;
321 
323  }
324  else
325  EnumDependUsage();
326  }
327  else
328  {
329  MainUsage();
330  }
331 
332  return 0;
333 }
#define _tprintf
Definition: tchar.h:506
BOOL SetDescription(LPCTSTR ServiceName, LPCTSTR Description)
Definition: description.c:99
VOID EnumDependUsage(VOID)
Definition: usage.c:285
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define lstrcmpi
Definition: winbase.h:3687
BOOL GetDisplayName(LPCTSTR ServiceName)
Definition: name.c:12
BOOL SetFailure(LPCTSTR *ServiceArgs, INT ArgCount)
Definition: failure.c:120
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
VOID GetDisplayNameUsage(VOID)
Definition: usage.c:268
_In_ BOOLEAN Create
Definition: pstypes.h:511
VOID InterrogateUsage(VOID)
Definition: usage.c:110
VOID StartUsage(VOID)
Definition: usage.c:93
VOID SdShowUsage(VOID)
Definition: usage.c:181
static const WCHAR Description[]
Definition: oid.c:1266
Definition: shell.h:41
static void Server(int port)
Definition: srltest.c:69
VOID StopUsage(VOID)
Definition: usage.c:119
int32_t INT
Definition: typedefs.h:56
VOID ControlUsage(VOID)
Definition: usage.c:169
BOOL QueryDescription(LPCTSTR ServiceName)
Definition: description.c:12
BOOL SdShow(LPCTSTR ServiceName)
Definition: sdshow.c:12
#define SERVICE_CONTROL_PARAMCHANGE
Definition: winsvc.h:41
VOID DeleteUsage(VOID)
Definition: usage.c:135
VOID SetDescriptionUsage(VOID)
Definition: usage.c:221
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
BOOL SetConfig(LPCTSTR *ServiceArgs, INT ArgCount)
Definition: config.c:199
VOID SdSetUsage(VOID)
Definition: usage.c:189
#define _T(x)
Definition: vfdio.h:22
LPTSTR ServiceName
Definition: ServiceMain.c:15
BOOL SdSet(LPCTSTR ServiceName, LPCTSTR SecurityDescriptor)
Definition: sdset.c:12
VOID QueryDescriptionUsage(VOID)
Definition: usage.c:205
VOID PauseUsage(VOID)
Definition: usage.c:102
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
Definition: query.c:292
Definition: partlist.h:33
VOID QueryConfigUsage(VOID)
Definition: usage.c:197
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_NETBINDADD
Definition: winsvc.h:42
BOOL QueryFailure(LPCTSTR ServiceName)
Definition: failure.c:11
static const WCHAR Control[]
Definition: interface.c:27
VOID ContinueUsage(VOID)
Definition: usage.c:127
VOID QueryFailureUsage(VOID)
Definition: usage.c:213
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
BOOL EnumDepend(LPCTSTR ServiceName)
Definition: depend.c:12
int CDECL _ttoi(const _TCHAR *str)
Definition: atoi.c:10
#define SERVICE_CONTROL_NETBINDENABLE
Definition: winsvc.h:44
VOID MainUsage(VOID)
Definition: usage.c:14
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_CONTROL_NETBINDDISABLE
Definition: winsvc.h:45
#define SERVICE_CONTROL_NETBINDREMOVE
Definition: winsvc.h:43
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
BOOL QueryConfig(LPCTSTR ServiceName)
Definition: config.c:12
VOID GetKeyNameUsage(VOID)
Definition: usage.c:276
BOOL GetKeyName(LPWSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCWSTR lpSubKey)
Definition: edit.c:1588

Referenced by _tmain().

Variable Documentation

◆ hSCManager

SC_HANDLE hSCManager

Definition at line 12 of file sc.c.

Referenced by AddService(), Control(), Create(), CreateServiceA(), CreateServiceW(), Delete(), DoControlService(), DoCreate(), DoDeleteService(), DoStartService(), DoStopService(), EnableUserModePnpManager(), EnumServiceGroupW(), EnumServices(), EnumServicesStatusA(), EnumServicesStatusExA(), EnumServicesStatusExW(), EnumServicesStatusW(), GetServiceConfig(), GetServiceDescription(), GetServiceDisplayNameA(), GetServiceDisplayNameW(), GetServiceKeyNameA(), GetServiceKeyNameW(), GetServices(), I_ScGetCurrentGroupStateW(), InstallOneService(), LockServiceDatabase(), MMSYS_InstallDevice(), OpenServiceA(), OpenServiceW(), PlayLogonSoundThread(), QueryService(), QueryServiceLockStatusA(), QueryServiceLockStatusW(), RCreateServiceA(), RCreateServiceW(), RegisterDriver(), REnumServiceGroupW(), REnumServicesStatusA(), REnumServicesStatusExA(), REnumServicesStatusExW(), REnumServicesStatusW(), RGetServiceDisplayNameA(), RGetServiceDisplayNameW(), RGetServiceKeyNameA(), RGetServiceKeyNameW(), RI_ScGetCurrentGroupStateW(), RI_ScQueryServiceTagInfo(), RLockServiceDatabase(), ROpenServiceA(), ROpenServiceW(), RpcSsConfigureAsNetworkService(), RQueryServiceLockStatusA(), RQueryServiceLockStatusW(), ServicesPageWndProc(), SetServiceAccount(), SetServiceConfig(), SetServiceDescription(), Start(), StartAudioService(), StartDriver(), StartSystemAudioServices(), StopDriver(), TV1_AddDependantsToTree(), TV2_GetDependants(), TV2_HasDependantServices(), and UnregisterDriver().