ReactOS 0.4.15-dev-5666-gc548b97
cmdStart.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/cmdStart.c
5 * PURPOSE:
6 *
7 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
8 */
9
10#include "net.h"
11
12/* Enumerate all running services */
13static
14INT
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 BOOL ret;
27
28 hManager = OpenSCManagerW(NULL,
31 if (hManager == NULL)
32 {
33 dwError = GetLastError();
34 nError = 1;
35 goto done;
36 }
37
38 ret = EnumServicesStatusW(hManager,
41 NULL,
42 0,
43 &dwBufferSize,
44 &dwServiceCount,
45 &dwResumeHandle);
46 if (ret)
47 {
48 /* Nothing to enumerate ?! */
49 goto done;
50 }
51 dwError = GetLastError();
52 if (dwError != ERROR_INSUFFICIENT_BUFFER)
53 goto done;
54
55 if (dwBufferSize != 0)
56 {
57 lpServiceBuffer = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
58 if (lpServiceBuffer != NULL)
59 {
60 if (EnumServicesStatusW(hManager,
63 lpServiceBuffer,
64 dwBufferSize,
65 &dwBufferSize,
66 &dwServiceCount,
67 &dwResumeHandle))
68 {
69 ConPuts(StdOut, L"The following services have been started:\n\n");
70
71 for (i = 0; i < dwServiceCount; i++)
72 {
73 ConPrintf(StdOut, L" %s\n", lpServiceBuffer[i].lpDisplayName);
74 }
75 }
76
77 HeapFree(GetProcessHeap(), 0, lpServiceBuffer);
78 }
79 }
80
81done:
82 if (hService != NULL)
83 CloseServiceHandle(hService);
84
85 if (hManager != NULL)
86 CloseServiceHandle(hManager);
87
88 if (dwError != ERROR_SUCCESS)
89 {
90 /* FIXME: Print proper error message */
91 ConPrintf(StdErr, L"Error: %lu\n", dwError);
92 }
93
94 return nError;
95}
96
97/* Start the service argv[2] */
98static
99INT
101{
102 SC_HANDLE hManager = NULL;
103 SC_HANDLE hService = NULL;
104 LPCWSTR *lpArgVectors = NULL;
105 DWORD dwError = ERROR_SUCCESS;
106 INT nError = 0;
107 INT i;
108
109 hManager = OpenSCManagerW(NULL,
112 if (hManager == NULL)
113 {
114 dwError = GetLastError();
115 nError = 1;
116 goto done;
117 }
118
119 hService = OpenServiceW(hManager,
120 argv[2],
122 if (hService == NULL)
123 {
124 dwError = GetLastError();
125 nError = 1;
126 goto done;
127 }
128
129 lpArgVectors = HeapAlloc(GetProcessHeap(),
130 0,
131 (argc - 2) * sizeof(LPCWSTR));
132 if (lpArgVectors == NULL)
133 {
134 dwError = GetLastError();
135 nError = 1;
136 goto done;
137 }
138
139 for (i = 2; i < argc; i++)
140 {
141 lpArgVectors[i - 2] = argv[i];
142 }
143
144 if (!StartServiceW(hService,
145 (DWORD)argc - 2,
146 lpArgVectors))
147 {
148 dwError = GetLastError();
149 nError = 1;
150 }
151
152done:
153 if (lpArgVectors != NULL)
154 HeapFree(GetProcessHeap(), 0, (LPVOID)lpArgVectors);
155
156 if (hService != NULL)
157 CloseServiceHandle(hService);
158
159 if (hManager != NULL)
160 CloseServiceHandle(hManager);
161
162 if (dwError != ERROR_SUCCESS)
163 {
164 /* FIXME: Print proper error message */
165 ConPrintf(StdErr, L"Error: %lu\n", dwError);
166 }
167
168 return nError;
169}
170
171INT
173{
174 INT i;
175
176 if (argc == 2)
177 {
179 }
180
181 for (i = 2; i < argc; i++)
182 {
183 if (_wcsicmp(argv[i], L"/help") == 0)
184 {
185 PrintMessageString(4381);
186 ConPuts(StdOut, L"\n");
187 PrintNetMessage(MSG_START_SYNTAX);
188 PrintNetMessage(MSG_START_HELP);
189 return 1;
190 }
191 }
192
193 return StartOneService(argc, argv);
194}
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
#define StdErr
Definition: fc.c:15
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
static INT StartOneService(INT argc, WCHAR **argv)
Definition: cmdStart.c:100
INT cmdStart(INT argc, WCHAR **argv)
Definition: cmdStart.c:172
static INT EnumerateRunningServices(VOID)
Definition: cmdStart.c:15
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2016
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2108
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2928
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
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:1316
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Deprecated header file that includes net_sockets.h.
int32_t INT
Definition: typedefs.h:58
int ret
_In_ LPCSTR _Out_writes_to_opt_ cchDisplayName LPSTR lpDisplayName
Definition: winbase.h:2777
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define SERVICE_START
Definition: winsvc.h:57
#define SERVICE_ACTIVE
Definition: winsvc.h:50
#define SC_MANAGER_ENUMERATE_SERVICE
Definition: winsvc.h:16
#define SERVICES_ACTIVE_DATABASE
Definition: winsvc.h:564
#define SERVICE_WIN32
Definition: cmtypes.h:964
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185