26 #define SIP(String, Integer) { (String), (PVOID)(Integer) }
30 SIP(L
"Stopped", SERVICE_STOPPED),
31 SIP(L
"Start Pending", SERVICE_START_PENDING),
32 SIP(L
"Stop Pending", SERVICE_STOP_PENDING),
33 SIP(L
"Running", SERVICE_RUNNING),
34 SIP(L
"Continue Pending", SERVICE_CONTINUE_PENDING),
35 SIP(L
"Pause Pending", SERVICE_PAUSE_PENDING),
36 SIP(L
"Paused", SERVICE_PAUSED)
41 SIP(L
"Driver", SERVICE_KERNEL_DRIVER),
42 SIP(L
"FS Driver", SERVICE_FILE_SYSTEM_DRIVER),
43 SIP(L
"Own Process", SERVICE_WIN32_OWN_PROCESS),
44 SIP(L
"Share Process", SERVICE_WIN32_SHARE_PROCESS),
45 SIP(L
"Own Interactive Process", SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS),
46 SIP(L
"Share Interactive Process", SERVICE_WIN32_SHARE_PROCESS | SERVICE_INTERACTIVE_PROCESS)
51 SIP(L
"Disabled", SERVICE_DISABLED),
52 SIP(L
"Boot Start", SERVICE_BOOT_START),
53 SIP(L
"System Start", SERVICE_SYSTEM_START),
54 SIP(L
"Auto Start", SERVICE_AUTO_START),
55 SIP(L
"Demand Start", SERVICE_DEMAND_START)
60 SIP(L
"Ignore", SERVICE_ERROR_IGNORE),
61 SIP(L
"Normal", SERVICE_ERROR_NORMAL),
62 SIP(L
"Severe", SERVICE_ERROR_SEVERE),
63 SIP(L
"Critical", SERVICE_ERROR_CRITICAL)
67 L
"Own Interactive Process", L
"Share Interactive Process" };
69 L
"Auto Start", L
"Demand Start" };
73 _In_ SC_HANDLE ScManagerHandle,
79 static ULONG initialBufferSize = 0x8000;
84 ULONG servicesReturned;
87 Type = SERVICE_DRIVER | SERVICE_WIN32;
89 State = SERVICE_STATE_ALL;
91 bufferSize = initialBufferSize;
92 buffer = PhAllocate(bufferSize);
94 if (!(result = EnumServicesStatusEx(
107 if (GetLastError() == ERROR_MORE_DATA)
110 bufferSize += returnLength;
111 buffer = PhAllocate(bufferSize);
113 result = EnumServicesStatusEx(
115 SC_ENUM_PROCESS_INFO,
134 if (bufferSize <= 0x20000) initialBufferSize = bufferSize;
135 *Count = servicesReturned;
142 _In_ ACCESS_MASK DesiredAccess
145 SC_HANDLE scManagerHandle;
146 SC_HANDLE serviceHandle;
148 scManagerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
150 if (!scManagerHandle)
153 serviceHandle = OpenService(scManagerHandle, ServiceName, DesiredAccess);
154 CloseServiceHandle(scManagerHandle);
156 return serviceHandle;
160 _In_ SC_HANDLE ServiceHandle
164 ULONG bufferSize = 0x200;
166 buffer = PhAllocate(bufferSize);
168 if (!QueryServiceConfig(ServiceHandle, buffer, bufferSize, &bufferSize))
171 buffer = PhAllocate(bufferSize);
173 if (!QueryServiceConfig(ServiceHandle, buffer, bufferSize, &bufferSize))
184 _In_ SC_HANDLE ServiceHandle,
189 ULONG bufferSize = 0x100;
191 buffer = PhAllocate(bufferSize);
193 if (!QueryServiceConfig2(
202 buffer = PhAllocate(bufferSize);
204 if (!QueryServiceConfig2(
221 _In_ SC_HANDLE ServiceHandle
225 LPSERVICE_DESCRIPTION serviceDescription;
229 if (serviceDescription)
231 if (serviceDescription->lpDescription)
234 PhFree(serviceDescription);
245 _In_ SC_HANDLE ServiceHandle,
246 _Out_ PBOOLEAN DelayedAutoStart
249 SERVICE_DELAYED_AUTO_START_INFO delayedAutoStartInfo;
252 if (QueryServiceConfig2(
254 SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
255 (BYTE *)&delayedAutoStartInfo,
256 sizeof(SERVICE_DELAYED_AUTO_START_INFO),
260 *DelayedAutoStart = !!delayedAutoStartInfo.fDelayedAutostart;
270 _In_ SC_HANDLE ServiceHandle,
271 _In_ BOOLEAN DelayedAutoStart
274 SERVICE_DELAYED_AUTO_START_INFO delayedAutoStartInfo;
276 delayedAutoStartInfo.fDelayedAutostart = DelayedAutoStart;
278 return !!ChangeServiceConfig2(
280 SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
281 &delayedAutoStartInfo
286 _In_ ULONG ServiceState
292 PhpServiceStatePairs,
293 sizeof(PhpServiceStatePairs),
303 _In_ ULONG ServiceType
310 sizeof(PhpServiceTypePairs),
320 _In_ PWSTR ServiceType
327 sizeof(PhpServiceTypePairs),
337 _In_ ULONG ServiceStartType
343 PhpServiceStartTypePairs,
344 sizeof(PhpServiceStartTypePairs),
354 _In_ PWSTR ServiceStartType
360 PhpServiceStartTypePairs,
361 sizeof(PhpServiceStartTypePairs),
371 _In_ ULONG ServiceErrorControl
377 PhpServiceErrorControlPairs,
378 sizeof(PhpServiceErrorControlPairs),
388 _In_ PWSTR ServiceErrorControl
394 PhpServiceErrorControlPairs,
395 sizeof(PhpServiceErrorControlPairs),
406 _In_ PVOID ServiceTag
413 if (!I_QueryTagInformation)
417 if (!I_QueryTagInformation)
437 _In_ HANDLE ThreadHandle,
438 _In_opt_ HANDLE ProcessHandle,
439 _Out_ PVOID *ServiceTag
444 BOOLEAN openedProcessHandle =
FALSE;
458 openedProcessHandle =
TRUE;
469 if (openedProcessHandle)
470 NtClose(ProcessHandle);
505 *ServiceDll = expandedString;
510 *ServiceDll = serviceDllString;
515 status = STATUS_NOT_FOUND;