ReactOS  0.4.12-dev-685-gf36cbf7
config.c File Reference
#include "sc.h"
Include dependency graph for config.c:

Go to the source code of this file.

Functions

BOOL QueryConfig (LPCTSTR ServiceName)
 
BOOL SetConfig (LPCTSTR *ServiceArgs, INT ArgCount)
 

Function Documentation

◆ QueryConfig()

BOOL QueryConfig ( LPCTSTR  ServiceName)

Definition at line 12 of file config.c.

13 {
14  SC_HANDLE hManager = NULL;
15  SC_HANDLE hService = NULL;
16  BOOL bResult = TRUE;
17  DWORD cbBytesNeeded = 0;
18  LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
19  LPWSTR lpPtr;
20  SSIZE_T nLen, i;
21 
22 #ifdef SCDBG
23  _tprintf(_T("service to show configuration - %s\n\n"), ServiceName);
24 #endif
25 
26  hManager = OpenSCManager(NULL,
27  NULL,
29  if (hManager == NULL)
30  {
31  _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
32  bResult = FALSE;
33  goto done;
34  }
35 
36  hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
37  if (hService == NULL)
38  {
39  _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
40  bResult = FALSE;
41  goto done;
42  }
43 
44  if (!QueryServiceConfig(hService,
45  NULL,
46  0,
47  &cbBytesNeeded))
48  {
49  if (cbBytesNeeded == 0)
50  {
51  _tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
52  bResult = FALSE;
53  goto done;
54  }
55  }
56 
57  pServiceConfig = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
58  if (pServiceConfig == NULL)
59  {
61  _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
62  bResult = FALSE;
63  goto done;
64  }
65 
66  if (!QueryServiceConfig(hService,
67  pServiceConfig,
68  cbBytesNeeded,
69  &cbBytesNeeded))
70  {
71  _tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
72  bResult = FALSE;
73  goto done;
74  }
75 
76  _tprintf(_T("[SC] QueryServiceConfig SUCCESS\n\n"));
77 
78  _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
79  _tprintf(_T(" TYPE : %-3lx "), pServiceConfig->dwServiceType);
80  switch (pServiceConfig->dwServiceType)
81  {
83  _tprintf(_T("KERNEL_DRIVER\n"));
84  break;
85 
87  _tprintf(_T("FILE_SYSTEM_DRIVER\n"));
88  break;
89 
91  _tprintf(_T("WIN32_OWN_PROCESS\n"));
92  break;
93 
95  _tprintf(_T("WIN32_SHARE_PROCESS\n"));
96  break;
97 
99  _tprintf(_T("WIN32_OWN_PROCESS (interactive)\n"));
100  break;
101 
103  _tprintf(_T("WIN32_SHARE_PROCESS (interactive)\n"));
104  break;
105 
106  default:
107  _tprintf(_T("\n"));
108  break;
109  }
110 
111  _tprintf(_T(" START_TYPE : %-3lx "), pServiceConfig->dwStartType);
112  switch (pServiceConfig->dwStartType)
113  {
114  case SERVICE_BOOT_START:
115  _tprintf(_T("BOOT_START\n"));
116  break;
117 
119  _tprintf(_T("SYSTEM_START\n"));
120  break;
121 
122  case SERVICE_AUTO_START:
123  _tprintf(_T("AUTO_START\n"));
124  break;
125 
127  _tprintf(_T("DEMAND_START\n"));
128  break;
129 
130  case SERVICE_DISABLED:
131  _tprintf(_T("DISABLED\n"));
132  break;
133 
134  default:
135  _tprintf(_T("\n"));
136  break;
137  }
138 
139  _tprintf(_T(" ERROR_CONTROL : %-3lx "), pServiceConfig->dwErrorControl);
140  switch (pServiceConfig->dwErrorControl)
141  {
143  _tprintf(_T("IGNORE\n"));
144  break;
145 
147  _tprintf(_T("NORMAL\n"));
148  break;
149 
151  _tprintf(_T("SEVERE\n"));
152  break;
153 
155  _tprintf(_T("CRITICAL\n"));
156  break;
157 
158  default:
159  _tprintf(_T("\n"));
160  break;
161  }
162 
163  _tprintf(_T(" BINARY_PATH_NAME : %s\n"), pServiceConfig->lpBinaryPathName);
164  _tprintf(_T(" LOAD_ORDER_GROUP : %s\n"), pServiceConfig->lpLoadOrderGroup);
165  _tprintf(_T(" TAG : %lu\n"), pServiceConfig->dwTagId);
166  _tprintf(_T(" DISPLAY_NAME : %s\n"), pServiceConfig->lpDisplayName);
167  _tprintf(_T(" DEPENDENCIES : "));
168  lpPtr = pServiceConfig->lpDependencies;
169  i = 0;
170  while (*lpPtr != _T('\0'))
171  {
172  nLen = _tcslen(lpPtr);
173  if (i != 0)
174  _tprintf(_T("\n : "));
175  _tprintf(_T("%s"), lpPtr);
176  lpPtr = lpPtr + nLen + 1;
177  i++;
178  }
179  _tprintf(_T("\n"));
180 
181  _tprintf(_T(" SERVICE_START_NAME : %s\n"), pServiceConfig->lpServiceStartName);
182 
183 done:
184  if (bResult == FALSE)
185  ReportLastError();
186 
187  if (pServiceConfig != NULL)
188  HeapFree(GetProcessHeap(), 0, pServiceConfig);
189 
190  if (hService)
191  CloseServiceHandle(hService);
192 
193  if (hManager)
194  CloseServiceHandle(hManager);
195 
196  return bResult;
197 }
#define SERVICE_ERROR_IGNORE
Definition: cmtypes.h:979
#define _tprintf
Definition: tchar.h:506
#define SERVICE_SYSTEM_START
Definition: cmtypes.h:974
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:980
#define TRUE
Definition: types.h:120
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
LPSTR lpServiceStartName
Definition: winsvc.h:152
#define SERVICE_INTERACTIVE_PROCESS
Definition: cmtypes.h:965
#define QueryServiceConfig
Definition: winsvc.h:580
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LONG_PTR SSIZE_T
Definition: basetsd.h:183
#define OpenService
Definition: winsvc.h:576
#define SERVICE_DISABLED
Definition: cmtypes.h:977
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
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_BOOT_START
Definition: cmtypes.h:973
#define SERVICE_FILE_SYSTEM_DRIVER
Definition: cmtypes.h:952
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#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 GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:961
VOID ReportLastError(VOID)
Definition: sc.c:15
#define SERVICE_ERROR_SEVERE
Definition: cmtypes.h:981
#define SERVICE_AUTO_START
Definition: cmtypes.h:975
#define SERVICE_ERROR_CRITICAL
Definition: cmtypes.h:982
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:951

Referenced by ScControl().

◆ SetConfig()

BOOL SetConfig ( LPCTSTR ServiceArgs,
INT  ArgCount 
)

Definition at line 199 of file config.c.

200 {
201  SC_HANDLE hManager = NULL;
202  SC_HANDLE hService = NULL;
203  BOOL bResult = TRUE;
205 
206  if (!ParseCreateConfigArguments(ServiceArgs, ArgCount, TRUE, &ServiceInfo))
207  {
208  SetConfigUsage();
209  return FALSE;
210  }
211 
212 #ifdef SCDBG
213  _tprintf(_T("service name - %s\n"), ServiceInfo.lpServiceName);
214  _tprintf(_T("display name - %s\n"), ServiceInfo.lpDisplayName);
215  _tprintf(_T("service type - %lu\n"), ServiceInfo.dwServiceType);
216  _tprintf(_T("start type - %lu\n"), ServiceInfo.dwStartType);
217  _tprintf(_T("error control - %lu\n"), ServiceInfo.dwErrorControl);
218  _tprintf(_T("Binary path - %s\n"), ServiceInfo.lpBinaryPathName);
219  _tprintf(_T("load order group - %s\n"), ServiceInfo.lpLoadOrderGroup);
220  _tprintf(_T("tag - %lu\n"), ServiceInfo.dwTagId);
221  _tprintf(_T("dependencies - %s\n"), ServiceInfo.lpDependencies);
222  _tprintf(_T("account start name - %s\n"), ServiceInfo.lpServiceStartName);
223  _tprintf(_T("account password - %s\n"), ServiceInfo.lpPassword);
224 #endif
225 
226  hManager = OpenSCManager(NULL,
227  NULL,
229  if (hManager == NULL)
230  {
231  _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
232  bResult = FALSE;
233  goto done;
234  }
235 
236  hService = OpenService(hManager,
237  ServiceInfo.lpServiceName,
239  if (hService == NULL)
240  {
241  _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
242  bResult = FALSE;
243  goto done;
244  }
245 
246  if (!ChangeServiceConfig(hService,
247  ServiceInfo.dwServiceType,
248  ServiceInfo.dwStartType,
249  ServiceInfo.dwErrorControl,
250  ServiceInfo.lpBinaryPathName,
251  ServiceInfo.lpLoadOrderGroup,
252  ServiceInfo.bTagId ? &ServiceInfo.dwTagId : NULL,
253  ServiceInfo.lpDependencies,
254  ServiceInfo.lpServiceStartName,
255  ServiceInfo.lpPassword,
256  ServiceInfo.lpDisplayName))
257  {
258  _tprintf(_T("[SC] ChangeServiceConfig FAILED %lu:\n\n"), GetLastError());
259  bResult = FALSE;
260  goto done;
261  }
262 
263  _tprintf(_T("[SC] ChangeServiceConfig SUCCESS\n\n"));
264 
265 done:
266  if (bResult == FALSE)
267  ReportLastError();
268 
269  if (hService)
270  CloseServiceHandle(hService);
271 
272  if (hManager)
273  CloseServiceHandle(hManager);
274 
275  return bResult;
276 }
#define _tprintf
Definition: tchar.h:506
#define TRUE
Definition: types.h:120
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
JS_SERVICE_STATE ServiceInfo(LPCTSTR ServiceName)
Return service status by service name.
Definition: user_lib.cpp:157
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define OpenService
Definition: winsvc.h:576
#define ChangeServiceConfig
Definition: winsvc.h:567
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
#define OpenSCManager
Definition: winsvc.h:575
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
VOID SetConfigUsage(VOID)
Definition: usage.c:229
VOID ReportLastError(VOID)
Definition: sc.c:15
BOOL ParseCreateConfigArguments(LPCTSTR *ServiceArgs, INT ArgCount, BOOL bChangeService, OUT LPSERVICE_CREATE_INFO lpServiceInfo)
Definition: misc.c:53

Referenced by DECLARE_INTERFACE_(), and ScControl().