2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/query.c
5 * PURPOSE: Query service information
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
13 ENUM_SERVICE_STATUS_PROCESS
*
14 GetSelectedService(PMAIN_WND_INFO Info
)
18 lvItem
.mask
= LVIF_PARAM
;
19 lvItem
.iItem
= Info
->SelectedItem
;
20 SendMessage(Info
->hListView
,
25 /* return pointer to selected service */
26 return (ENUM_SERVICE_STATUS_PROCESS
*)lvItem
.lParam
;
30 LPQUERY_SERVICE_CONFIG
31 GetServiceConfig(LPTSTR lpServiceName
)
33 SC_HANDLE hSCManager
= NULL
;
35 LPQUERY_SERVICE_CONFIG pServiceConfig
= NULL
;
36 DWORD BytesNeeded
= 0;
38 hSCManager
= OpenSCManager(NULL
,
40 SC_MANAGER_ENUMERATE_SERVICE
);
41 if (hSCManager
== NULL
)
47 hSc
= OpenService(hSCManager
,
49 SERVICE_QUERY_CONFIG
);
56 if (!QueryServiceConfig(hSc
,
61 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
63 pServiceConfig
= (LPQUERY_SERVICE_CONFIG
) HeapAlloc(ProcessHeap
,
66 if (pServiceConfig
== NULL
)
69 if (!QueryServiceConfig(hSc
,
78 pServiceConfig
= NULL
;
84 if (hSCManager
!= NULL
)
85 CloseServiceHandle(hSCManager
);
87 CloseServiceHandle(hSc
);
89 return pServiceConfig
;
94 SetServiceConfig(LPQUERY_SERVICE_CONFIG pServiceConfig
,
103 hSCManager
= OpenSCManager(NULL
,
108 scLock
= LockServiceDatabase(hSCManager
);
111 hSc
= OpenService(hSCManager
,
113 SERVICE_CHANGE_CONFIG
);
116 if (ChangeServiceConfig(hSc
,
117 pServiceConfig
->dwServiceType
,
118 pServiceConfig
->dwStartType
,
119 pServiceConfig
->dwErrorControl
,
120 pServiceConfig
->lpBinaryPathName
,
121 pServiceConfig
->lpLoadOrderGroup
,
122 pServiceConfig
->dwTagId
? &pServiceConfig
->dwTagId
: NULL
,
123 pServiceConfig
->lpDependencies
,
124 pServiceConfig
->lpServiceStartName
,
126 pServiceConfig
->lpDisplayName
))
132 UnlockServiceDatabase(scLock
);
144 GetServiceDescription(LPTSTR lpServiceName
)
146 SC_HANDLE hSCManager
= NULL
;
147 SC_HANDLE hSc
= NULL
;
148 SERVICE_DESCRIPTION
*pServiceDescription
= NULL
;
149 LPTSTR lpDescription
= NULL
;
150 DWORD BytesNeeded
= 0;
152 hSCManager
= OpenSCManager(NULL
,
154 SC_MANAGER_ENUMERATE_SERVICE
);
155 if (hSCManager
== NULL
)
161 hSc
= OpenService(hSCManager
,
163 SERVICE_QUERY_CONFIG
);
166 if (!QueryServiceConfig2(hSc
,
167 SERVICE_CONFIG_DESCRIPTION
,
172 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
174 pServiceDescription
= (SERVICE_DESCRIPTION
*) HeapAlloc(ProcessHeap
,
177 if (pServiceDescription
== NULL
)
180 if (QueryServiceConfig2(hSc
,
181 SERVICE_CONFIG_DESCRIPTION
,
182 (LPBYTE
)pServiceDescription
,
186 if (pServiceDescription
->lpDescription
)
188 lpDescription
= HeapAlloc(ProcessHeap
,
190 (_tcslen(pServiceDescription
->lpDescription
) + 1) * sizeof(TCHAR
));
192 _tcscpy(lpDescription
,
193 pServiceDescription
->lpDescription
);
201 if (pServiceDescription
)
202 HeapFree(ProcessHeap
,
204 pServiceDescription
);
205 if (hSCManager
!= NULL
)
206 CloseServiceHandle(hSCManager
);
208 CloseServiceHandle(hSc
);
210 return lpDescription
;
215 SetServiceDescription(LPTSTR lpServiceName
,
216 LPTSTR lpDescription
)
218 SC_HANDLE hSCManager
;
221 SERVICE_DESCRIPTION ServiceDescription
;
224 hSCManager
= OpenSCManager(NULL
,
229 scLock
= LockServiceDatabase(hSCManager
);
232 hSc
= OpenService(hSCManager
,
234 SERVICE_CHANGE_CONFIG
);
237 ServiceDescription
.lpDescription
= lpDescription
;
239 if (ChangeServiceConfig2(hSc
,
240 SERVICE_CONFIG_DESCRIPTION
,
241 &ServiceDescription
))
246 CloseServiceHandle(hSc
);
249 UnlockServiceDatabase(scLock
);
252 CloseServiceHandle(hSCManager
);
263 GetServiceList(PMAIN_WND_INFO Info
,
269 DWORD BytesNeeded
= 0;
270 DWORD ResumeHandle
= 0;
274 if (Info
->pAllServices
!= NULL
)
276 HeapFree(ProcessHeap
,
281 ScHandle
= OpenSCManager(NULL
,
283 SC_MANAGER_ENUMERATE_SERVICE
);
284 if (ScHandle
!= INVALID_HANDLE_VALUE
)
286 if (!EnumServicesStatusEx(ScHandle
,
287 SC_ENUM_PROCESS_INFO
,
297 /* Call function again if required size was returned */
298 if (GetLastError() == ERROR_MORE_DATA
)
300 /* reserve memory for service info array */
301 Info
->pAllServices
= (ENUM_SERVICE_STATUS_PROCESS
*) HeapAlloc(ProcessHeap
,
304 if (Info
->pAllServices
)
306 /* fill array with service info */
307 if (EnumServicesStatusEx(ScHandle
,
308 SC_ENUM_PROCESS_INFO
,
311 (LPBYTE
)Info
->pAllServices
,
326 CloseServiceHandle(ScHandle
);
330 HeapFree(ProcessHeap
,
340 UpdateServiceStatus(ENUM_SERVICE_STATUS_PROCESS
* pService
)
345 hScm
= OpenSCManager(NULL
,
347 SC_MANAGER_ENUMERATE_SERVICE
);
348 if (hScm
!= INVALID_HANDLE_VALUE
)
352 hService
= OpenService(hScm
,
353 pService
->lpServiceName
,
354 SERVICE_QUERY_STATUS
);
359 QueryServiceStatusEx(hService
,
360 SC_STATUS_PROCESS_INFO
,
361 (LPBYTE
)&pService
->ServiceStatusProcess
,