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

Go to the source code of this file.

Functions

static INT EnumerateRunningServices (VOID)
 
static INT StartOneService (INT argc, WCHAR **argv)
 
INT cmdStart (INT argc, WCHAR **argv)
 

Function Documentation

◆ cmdStart()

INT cmdStart ( INT  argc,
WCHAR **  argv 
)

Definition at line 163 of file cmdStart.c.

Referenced by CommandShell().

164 {
165  INT i;
166 
167  if (argc == 2)
168  {
169  return EnumerateRunningServices();
170  }
171 
172  for (i = 2; i < argc; i++)
173  {
174  if (_wcsicmp(argv[i], L"/help") == 0)
175  {
181  return 1;
182  }
183  }
184 
185  return StartOneService(argc, argv);
186 }
static int argc
Definition: ServiceArgs.c:12
static INT StartOneService(INT argc, WCHAR **argv)
Definition: cmdStart.c:91
int32_t INT
Definition: typedefs.h:56
static char ** argv
Definition: ServiceArgs.c:11
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define IDS_GENERIC_SYNTAX
Definition: resource.h:202
#define IDS_START_HELP_1
Definition: resource.h:67
#define IDS_START_HELP_2
Definition: resource.h:68
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
static INT EnumerateRunningServices(VOID)
Definition: cmdStart.c:15
#define StdOut
Definition: stream.h:76
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define IDS_START_SYNTAX
Definition: resource.h:66
#define IDS_START_HELP_3
Definition: resource.h:69

◆ EnumerateRunningServices()

static INT EnumerateRunningServices ( VOID  )
static

Definition at line 15 of file cmdStart.c.

Referenced by cmdStart().

16 {
17  SC_HANDLE hManager = NULL;
18  SC_HANDLE hService = NULL;
19  DWORD dwBufferSize = 0;
20  DWORD dwServiceCount;
21  DWORD dwResumeHandle = 0;
22  LPENUM_SERVICE_STATUSW lpServiceBuffer = NULL;
23  INT i;
24  INT nError = 0;
25  DWORD dwError = ERROR_SUCCESS;
26 
27  hManager = OpenSCManagerW(NULL,
30  if (hManager == NULL)
31  {
32  dwError = GetLastError();
33  nError = 1;
34  goto done;
35  }
36 
37  EnumServicesStatusW(hManager,
40  NULL,
41  0,
42  &dwBufferSize,
43  &dwServiceCount,
44  &dwResumeHandle);
45 
46  if (dwBufferSize != 0)
47  {
48  lpServiceBuffer = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
49  if (lpServiceBuffer != NULL)
50  {
51  if (EnumServicesStatusW(hManager,
54  lpServiceBuffer,
55  dwBufferSize,
56  &dwBufferSize,
57  &dwServiceCount,
58  &dwResumeHandle))
59  {
60  ConPuts(StdOut, L"The following services hav been started:\n\n");
61 
62  for (i = 0; i < dwServiceCount; i++)
63  {
64  ConPrintf(StdOut, L" %s\n", lpServiceBuffer[i].lpDisplayName);
65  }
66  }
67 
68  HeapFree(GetProcessHeap(), 0, lpServiceBuffer);
69  }
70  }
71 
72 done:
73  if (hService != NULL)
74  CloseServiceHandle(hService);
75 
76  if (hManager != NULL)
77  CloseServiceHandle(hManager);
78 
79  if (dwError != ERROR_SUCCESS)
80  {
81  /* FIXME: Print proper error message */
82  ConPrintf(StdErr, L"Error: %lu\n", dwError);
83  }
84 
85  return nError;
86 }
#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
BOOL WINAPI EnumServicesStatusW(SC_HANDLE hSCManager, DWORD dwServiceType, DWORD dwServiceState, LPENUM_SERVICE_STATUSW lpServices, DWORD cbBufSize, LPDWORD pcbBytesNeeded, LPDWORD lpServicesReturned, LPDWORD lpResumeHandle)
Definition: scm.c:1310
GLenum GLclampf GLint i
Definition: glfuncs.h:14
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
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define SERVICE_ACTIVE
Definition: winsvc.h:50
unsigned long DWORD
Definition: ntddk_ex.h:95
#define StdErr
Definition: stream.h:77
static const WCHAR L[]
Definition: oid.c:1087
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2010
#define SERVICE_WIN32
Definition: cmtypes.h:962
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76
_In_ LPCSTR _Out_writes_to_opt_ cchDisplayName LPSTR lpDisplayName
Definition: winbase.h:2730
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ StartOneService()

static INT StartOneService ( INT  argc,
WCHAR **  argv 
)
static

Definition at line 91 of file cmdStart.c.

Referenced by cmdStart().

92 {
93  SC_HANDLE hManager = NULL;
94  SC_HANDLE hService = NULL;
95  LPCWSTR *lpArgVectors = NULL;
96  DWORD dwError = ERROR_SUCCESS;
97  INT nError = 0;
98  INT i;
99 
100  hManager = OpenSCManagerW(NULL,
103  if (hManager == NULL)
104  {
105  dwError = GetLastError();
106  nError = 1;
107  goto done;
108  }
109 
110  hService = OpenServiceW(hManager,
111  argv[2],
112  SERVICE_START);
113  if (hService == NULL)
114  {
115  dwError = GetLastError();
116  nError = 1;
117  goto done;
118  }
119 
120  lpArgVectors = HeapAlloc(GetProcessHeap(),
121  0,
122  (argc - 2) * sizeof(LPCWSTR));
123  if (lpArgVectors == NULL)
124  {
125  dwError = GetLastError();
126  nError = 1;
127  goto done;
128  }
129 
130  for (i = 2; i < argc; i++)
131  {
132  lpArgVectors[i - 2] = argv[i];
133  }
134 
135  if (!StartServiceW(hService,
136  (DWORD)argc - 2,
137  lpArgVectors))
138  {
139  dwError = GetLastError();
140  nError = 1;
141  }
142 
143 done:
144  if (lpArgVectors != NULL)
145  HeapFree(GetProcessHeap(), 0, (LPVOID)lpArgVectors);
146 
147  if (hService != NULL)
148  CloseServiceHandle(hService);
149 
150  if (hManager != NULL)
151  CloseServiceHandle(hManager);
152 
153  if (dwError != ERROR_SUCCESS)
154  {
155  /* FIXME: Print proper error message */
156  ConPrintf(StdErr, L"Error: %lu\n", dwError);
157  }
158 
159  return nError;
160 }
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
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int32_t INT
Definition: typedefs.h:56
static char ** argv
Definition: ServiceArgs.c:11
GLenum GLclampf GLint i
Definition: glfuncs.h:14
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
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2922
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define StdErr
Definition: stream.h:77
static const WCHAR L[]
Definition: oid.c:1087
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2010
#define SERVICE_START
Definition: winsvc.h:57
#define HeapFree(x, y, z)
Definition: compat.h:394