2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/sc/config.c
5 * PURPOSE: Query/Set the service configuration
6 * COPYRIGHT: Copyright 2016 Eric Kohl
12 BOOL
QueryConfig(LPCTSTR ServiceName
)
14 SC_HANDLE hManager
= NULL
;
15 SC_HANDLE hService
= NULL
;
17 DWORD cbBytesNeeded
= 0;
18 LPQUERY_SERVICE_CONFIG pServiceConfig
= NULL
;
23 _tprintf(_T("service to show configuration - %s\n\n"), ServiceName
);
26 hManager
= OpenSCManager(NULL
,
31 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
36 hService
= OpenService(hManager
, ServiceName
, SERVICE_QUERY_CONFIG
);
39 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
44 if (!QueryServiceConfig(hService
,
49 if (cbBytesNeeded
== 0)
51 _tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
57 pServiceConfig
= HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded
);
58 if (pServiceConfig
== NULL
)
60 SetLastError(ERROR_OUTOFMEMORY
);
61 _tprintf(_T("[SC] HeapAlloc FAILED %lu:\n\n"), GetLastError());
66 if (!QueryServiceConfig(hService
,
71 _tprintf(_T("[SC] QueryServiceConfig FAILED %lu:\n\n"), GetLastError());
76 _tprintf(_T("[SC] QueryServiceConfig SUCCESS\n\n"));
78 _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName
);
79 _tprintf(_T(" TYPE : %-3lx "), pServiceConfig
->dwServiceType
);
80 switch (pServiceConfig
->dwServiceType
)
82 case SERVICE_KERNEL_DRIVER
:
83 _tprintf(_T("KERNEL_DRIVER\n"));
86 case SERVICE_FILE_SYSTEM_DRIVER
:
87 _tprintf(_T("FILE_SYSTEM_DRIVER\n"));
90 case SERVICE_WIN32_OWN_PROCESS
:
91 _tprintf(_T("WIN32_OWN_PROCESS\n"));
94 case SERVICE_WIN32_SHARE_PROCESS
:
95 _tprintf(_T("WIN32_SHARE_PROCESS\n"));
98 case SERVICE_WIN32_OWN_PROCESS
+ SERVICE_INTERACTIVE_PROCESS
:
99 _tprintf(_T("WIN32_OWN_PROCESS (interactive)\n"));
102 case SERVICE_WIN32_SHARE_PROCESS
+ SERVICE_INTERACTIVE_PROCESS
:
103 _tprintf(_T("WIN32_SHARE_PROCESS (interactive)\n"));
111 _tprintf(_T(" START_TYPE : %-3lx "), pServiceConfig
->dwStartType
);
112 switch (pServiceConfig
->dwStartType
)
114 case SERVICE_BOOT_START
:
115 _tprintf(_T("BOOT_START\n"));
118 case SERVICE_SYSTEM_START
:
119 _tprintf(_T("SYSTEM_START\n"));
122 case SERVICE_AUTO_START
:
123 _tprintf(_T("AUTO_START\n"));
126 case SERVICE_DEMAND_START
:
127 _tprintf(_T("DEMAND_START\n"));
130 case SERVICE_DISABLED
:
131 _tprintf(_T("DISABLED\n"));
139 _tprintf(_T(" ERROR_CONTROL : %-3lx "), pServiceConfig
->dwErrorControl
);
140 switch (pServiceConfig
->dwErrorControl
)
142 case SERVICE_ERROR_IGNORE
:
143 _tprintf(_T("IGNORE\n"));
146 case SERVICE_ERROR_NORMAL
:
147 _tprintf(_T("NORMAL\n"));
150 case SERVICE_ERROR_SEVERE
:
151 _tprintf(_T("SEVERE\n"));
154 case SERVICE_ERROR_CRITICAL
:
155 _tprintf(_T("CRITICAL\n"));
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
;
170 while (*lpPtr
!= _T('\0'))
172 nLen
= _tcslen(lpPtr
);
174 _tprintf(_T("\n : "));
175 _tprintf(_T("%s"), lpPtr
);
176 lpPtr
= lpPtr
+ nLen
+ 1;
181 _tprintf(_T(" SERVICE_START_NAME : %s\n"), pServiceConfig
->lpServiceStartName
);
184 if (bResult
== FALSE
)
187 if (pServiceConfig
!= NULL
)
188 HeapFree(GetProcessHeap(), 0, pServiceConfig
);
191 CloseServiceHandle(hService
);
194 CloseServiceHandle(hManager
);
199 BOOL
SetConfig(LPCTSTR
*ServiceArgs
, INT ArgCount
)
201 SC_HANDLE hManager
= NULL
;
202 SC_HANDLE hService
= NULL
;
204 SERVICE_CREATE_INFO ServiceInfo
;
206 if (!ParseCreateConfigArguments(ServiceArgs
, ArgCount
, TRUE
, &ServiceInfo
))
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
);
226 hManager
= OpenSCManager(NULL
,
229 if (hManager
== NULL
)
231 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
236 hService
= OpenService(hManager
,
237 ServiceInfo
.lpServiceName
,
238 SERVICE_CHANGE_CONFIG
);
239 if (hService
== NULL
)
241 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
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
))
258 _tprintf(_T("[SC] ChangeServiceConfig FAILED %lu:\n\n"), GetLastError());
263 _tprintf(_T("[SC] ChangeServiceConfig SUCCESS\n\n"));
266 if (bResult
== FALSE
)
270 CloseServiceHandle(hService
);
273 CloseServiceHandle(hManager
);