The QueryServiceStatusEx function retrieves the current status of the specified service based on the specified information level.
BOOL WINAPI QueryServiceStatusEx( _In_ SC_HANDLE hService, _In_ SC_STATUS_TYPE InfoLevel, _Out_opt_ LPBYTE lpBuffer, _In_ DWORD cbBufSize, _Out_ LPDWORD pcbBytesNeeded );
Currently, no other information levels are defined.
The maximum size of this array is 8K bytes. To determine the required size, specify NULL for this parameter and 0 for the cbBufSize parameter. The function will fail and GetLastError will return ERROR_INSUFFICIENT_BUFFER. The pcbBytesNeeded parameter will receive the required size.
If the function fails, the return value is zero. To get extended error information, call GetLastError. The following errors can be returned.
Return code | Description |
---|---|
ERROR_INVALID_HANDLE | The handle is invalid. |
ERROR_ACCESS_DENIED | The handle does not have the SERVICE_QUERY_STATUS access right. |
ERROR_INSUFFICIENT_BUFFER | The buffer is too small for the SERVICE_STATUS_PROCESS structure. Nothing was written to the structure. |
ERROR_INVALID_PARAMETER | The cbSize member of SERVICE_STATUS_PROCESS is not valid. |
ERROR_INVALID_LEVEL | The InfoLevel parameter contains an unsupported value. |
ERROR_SHUTDOWN_IN_PROGRESS | The system is shutting down; this function cannot be called. |
The QueryServiceStatusEx function returns the most recent service status information reported to the service control manager. If the service just changed its status, it may not have updated the service control manager yet. Applications can find the current service status by querying the service directly by using the ControlServicefunction with the SERVICE_CONTROL_INTERROGATE control code.
The process identifier returned in the SERVICE_STATUS_PROCESS structure is valid provided that the state of the service is one of SERVICE_RUNNING, SERVICE_PAUSE_PENDING, SERVICE_PAUSED, or SERVICE_CONTINUE_PENDING. If the service is in a SERVICE_START_PENDING or SERVICE_STOP_PENDING state, however, the process identifier may not be valid, and if the service is in the SERVICE_STOPPED state, it is never valid.
Client | Requires Windows XP or Windows 2000 Professional. |
---|---|
Server | Requires Windows Server 2003 or Windows 2000 Server. |
Header | Declared in Winsvc.h; include Windows.h. |
Library | Link to Advapi32.lib. |
DLL | Requires Advapi32.dll. |