3.1.4.14 REnumServicesStatusW (Opnum 14)
The REnumServicesStatusW method enumerates service records in the specified SCM database.
-
DWORD REnumServicesStatusW( [in] SC_RPC_HANDLE hSCManager, [in] DWORD dwServiceType, [in] DWORD dwServiceState, [out, size_is(cbBufSize)] LPBYTE lpBuffer, [in, range(0, 1024 * 256)] DWORD cbBufSize, [out] LPBOUNDED_DWORD_256K pcbBytesNeeded, [out] LPBOUNDED_DWORD_256K lpServicesReturned, [in, out, unique] LPBOUNDED_DWORD_256K lpResumeIndex );
hSCManager: An SC_RPC_HANDLE (section 2.2.4) data type that defines the handle to the SCM database that MUST have been created previously, using one of the open methods specified in section 3.1.4. The SC_MANAGER_ENUMERATE_SERVICE access right MUST have been granted to the caller when the RPC context handle to the service record was created.
dwServiceType: A value that specifies what types of service records to enumerate. This MUST be one or a combination of the following values.
-
Value
Meaning
SERVICE_KERNEL_DRIVER
0x00000001
A driver service. These are services that manage devices on the system
SERVICE_FILE_SYSTEM_DRIVER
0x00000002
A file system driver service. These are services that manage file systems on the system.
SERVICE_WIN32_OWN_PROCESS
0x00000010
Service that runs in its own process.
SERVICE_WIN32_SHARE_PROCESS
0x00000020
Service that shares a process with other services.
dwServiceState: A value that specifies the service records to enumerate based on the value of their ServiceStatus.dwCurrentState. This MUST be one of the following values.
-
Value
Meaning
SERVICE_ACTIVE
0x00000001
Enumerates service records that have ServiceStatus.dwCurrentState equal to one of the following: SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_RUNNING, SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING, and SERVICE_PAUSED.
SERVICE_INACTIVE
0x00000002
Enumerates service records that have ServiceStatus.dwCurrentState equal to SERVICE_STOPPED.
SERVICE_STATE_ALL
0x00000003
Enumerates service records that have ServiceStatus.dwCurrentState equal to one of the following: SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_RUNNING, SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING, SERVICE_PAUSED, and SERVICE_STOPPED.
lpBuffer: A pointer to an array of ENUM_SERVICE_STATUSW (section 2.2.11) structures that contain the name and service status information for each service in the database.
cbBufSize: The size, in bytes, of the array pointed to by the lpBuffer parameter.
pcbBytesNeeded: An LPBOUNDED_DWORD_256K (section 2.2.9) pointer to a variable that contains the number of bytes needed to store the array of service entries.
lpServicesReturned: An LPBOUNDED_DWORD_256K (section 2.2.9) pointer to a variable that contains the number of service entries returned.
lpResumeIndex: An LPBOUNDED_DWORD_256K (section 2.2.9) pointer to a variable that specifies the current position in the status enumeration. The server MUST assign a unique number to each service for the boot session, in increasing order, and increment that number by one for each service addition. The value of the lpResumeIndex parameter is one of these numbers, which the server can use to determine the resumption point for the enumeration.
Return Values: The method returns 0x00000000 (ERROR_SUCCESS) on success; otherwise, it returns one of the following error codes.
-
Return value/code
Description
5
ERROR_ACCESS_DENIED
The SM_MANAGER_ENUMERATE_SERVICE access right had not been granted to the caller when the RPC context handle to the service record was created.
6
ERROR_INVALID_HANDLE
The handle is no longer valid.
87
ERROR_INVALID_PARAMETER
A parameter that was specified is invalid.
234
ERROR_MORE_DATA
More data is available.
In response to this request from the client, for a successful operation the server MUST determine the list of service records in the SCM database identified by the hSCManager parameter with the current value of the ServiceStatus.dwCurrentState equal to the state specified by dwServiceState parameter and Type equal to the dwServiceType parameter of the client request. The server MUST return this list by setting the ServiceName, DisplayName, and ServiceStatus of each service in this list in the array of ENUM_SERVICE_STATUSW (section 2.2.11) structures pointed to by the lpBuffer parameter and MUST set the number of services returned in the lpServicesReturned parameter.
If the lpResumeIndex value is not zero, the server MUST use that as the offset to the list of services and return only services starting at this offset. If the lpResumeIndex value is zero, the server MUST return all services. The server MUST set this parameter to zero if the operation is successful. If the lpResumeIndex value is set by the client to any nonzero number not returned by the server, the behavior is not defined.
If the size of the lpBuffer array is insufficient for the list of service records returned, the server MUST fail the call with ERROR_MORE_DATA (234) and return the size in bytes required in the pcbBytesNeeded parameter. If the size is sufficient for data returned, the server also returns the required size, in bytes. The required size is dependent on the actual number of matching service records on the system.
If the size of the lpBuffer array is sufficient for the list of service records returned, the enumerated data MAY be in the buffer in a non-contiguous manner, and portions of the lpBuffer array MAY be empty (filled with 0x00).
The server MUST return ERROR_INVALID_PARAMETER (87) if a bitmask specified in the dwServiceState parameter is zero or contains undefined values.
The server MUST return ERROR_INVALID_PARAMETER (87) if a bitmask specified in the dwServiceType parameter is zero or contains undefined values.