EnumDependentServices

  BOOL EnumDependentServices(hService, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned)    
  SC_HANDLE hService;    
  DWORD dwServiceState;    
  LPENUM_SERVICE_STATUS lpServices;    
  DWORD cbBufSize;    
  LPDWORD pcbBytesNeeded;    
  LPDWORD lpServicesReturned;    

The EnumDependentServices function enumerates services that depend on the specified service.

Parameters

hService

Handle obtained from a previous OpenService call.

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. The services returned in this buffer is ordered by the reverse dependency order.

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.

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 SERVICE_ENUMERATE_DEPENDENTS 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 which depend on the specified service to be running before they can run. The returned services entries are ordered in the reverse order of the start dependencies with group order taken into account. Services can be stopped in the proper order based on the order of entries written to the output buffer.

The status of each service is returned with its name.