EnumServicesStatus

  BOOL EnumServicesStatus(hSCManager, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle)    
  SC_HANDLE hSCManager;    
  DWORD dwServiceType;    
  DWORD dwServiceState;    
  LPENUM_SERVICE_STATUS lpServices;    
  DWORD cbBufSize;    
  LPDWORD pcbBytesNeeded;    
  LPDWORD lpServicesReturned;    
  LPDWORD lpResumeHandle;    

The EnumServicesStatus function enumerates services in the Service Control Manager database along with the status of each service.

Parameters

hSCManager

Handle obtained from a previous OpenSCManager call.

dwServiceType

Value to select the type of services to enumerate. It must be one or the bitwise OR of the following values:

Value Meaning

SERVICE_WIN32 enumerate Win32 services only.
SERVICE_DRIVER enumerate Driver services only.

dwServiceState

Value to select the services to enumerate based on the running state. It must be one or the bitwise OR of the following values:

Value Meaning

SERVICE_ACTIVE enumerate services that have started which includes services that are running, paused, and in pending states.
SERVICE_INACTIVE enumerate services that are stopped.

lpServices

A pointer to a buffer to receive an array of service entries; each entry is the ENUM_SERVICE_STATUS information structure.

cbBufSize

Size of the buffer in bytes pointed to by lpServices.

pcbBytesNeeded

A pointer to a variable to receive the number of bytes needed to fit the remaining service entries.

lpServicesReturned

A pointer to a variable to receive the number of service entries returned.

lpResumeHandle

A pointer to a variable which on input specifies the starting point of enumeration. A value of 0 indicates to start at the beginning. On output, if this function returns FALSE and GetLastError indicates that ERROR_MORE_DATA has occurred, the handle returned specifies the next unread service entry. The returned handle is 0 if this function returns TRUE.

Return Value

Returns TRUE if all service entries are successfully written into the supplied output buffer. If the return value is FALSE, an error has occurred. Use GetLastError to determine the cause of the failure.

Errors Value Meaning
  ERROR_ACCESS_DENIED  
    The specified handle was not opened with SC_MANAGER_ENUMERATE_SERVICES access.
  ERROR_INVALID_HANDLE  
    The specified handle is invalid.
  ERROR_MORE_DATA  
    There are more service entries than would fit into the supplied output buffer. pcbBytesNeeded contains the number of bytes required to get the remaining entries. lpServicesReturned indicates the number of service entries that were written into the supplied output buffer. lpResumeHandle, if specified, contains the handle to the next service entry to resume the enumeration.
  ERROR_INVALID_PARAMETER  
    A parameter specified is invalid.

Comments

This function lists the services installed in the Service Control Manager database. The status of each service is returned with the name of the service.