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

Go to the source code of this file.

Functions

INT cmdStop (INT argc, WCHAR **argv)
 

Function Documentation

◆ cmdStop()

INT cmdStop ( INT  argc,
WCHAR **  argv 
)

Definition at line 12 of file cmdStop.c.

Referenced by CommandShell().

13 {
14  SC_HANDLE hManager = NULL;
15  SC_HANDLE hService = NULL;
17  DWORD dwError = ERROR_SUCCESS;
18  INT nError = 0;
19  INT i;
20 
21  if (argc != 3)
22  {
25  return 1;
26  }
27 
28  for (i = 2; i < argc; i++)
29  {
30  if (_wcsicmp(argv[i], L"/help") == 0)
31  {
37  return 1;
38  }
39  }
40 
41  hManager = OpenSCManagerW(NULL,
44  if (hManager == NULL)
45  {
46  dwError = GetLastError();
47  nError = 1;
48  goto done;
49  }
50 
51  hService = OpenServiceW(hManager,
52  argv[2],
53  SERVICE_STOP);
54  if (hService == NULL)
55  {
56  dwError = GetLastError();
57  nError = 1;
58  goto done;
59  }
60 
61  if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
62  {
63  dwError = GetLastError();
64  nError = 1;
65  goto done;
66  }
67 
68 done:
69  if (hService != NULL)
70  CloseServiceHandle(hService);
71 
72  if (hManager != NULL)
73  CloseServiceHandle(hManager);
74 
75  if (dwError != ERROR_SUCCESS)
76  {
77  /* FIXME: Print proper error message */
78  ConPrintf(StdErr, L"Error: %lu\n", dwError);
79  }
80 
81  return nError;
82 }
#define IDS_STOP_SYNTAX
Definition: resource.h:73
static int argc
Definition: ServiceArgs.c:12
#define SC_MANAGER_ENUMERATE_SERVICE
Definition: winsvc.h:16
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SERVICES_ACTIVE_DATABASE
Definition: winsvc.h:564
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int32_t INT
Definition: typedefs.h:56
#define IDS_STOP_HELP_1
Definition: resource.h:74
static char ** argv
Definition: ServiceArgs.c:11
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define IDS_GENERIC_SYNTAX
Definition: resource.h:202
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2102
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define StdErr
Definition: stream.h:77
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2010
#define IDS_STOP_HELP_3
Definition: resource.h:76
#define SERVICE_STOP
Definition: winsvc.h:58
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:618
SERVICE_STATUS ServiceStatus
Definition: dhcpcsvc.c:18
#define StdOut
Definition: stream.h:76
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define IDS_STOP_HELP_2
Definition: resource.h:75
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)