EnumDependentServices

来源:互联网 发布:防霾口罩 知乎 编辑:程序博客网 时间:2024/05/13 17:44

EnumDependentServices

The EnumDependentServices function retrieves the name and status of each service that depends on the specified service; that is, the specified service must be running before the dependent services can run.

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

Parameters

hService
[in] Handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the SERVICE_ENUMERATE_DEPENDENTS access right. For more information, see Service Security and Access Rights.
dwServiceState
[in] Services to enumerate based on their state. This parameter can be one of the following values. ValueMeaningSERVICE_ACTIVE
0x00000001Enumerates services that are in the following states: SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_RUNNING, SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING, and SERVICE_PAUSED.SERVICE_INACTIVE
0x00000002Enumerates services that are in the SERVICE_STOPPED state.SERVICE_STATE_ALL
0x00000003Combines the following states: SERVICE_ACTIVE and SERVICE_INACTIVE.
lpServices
[out] Pointer to an array of ENUM_SERVICE_STATUS structures that receives the name and service status information for each dependent service in the database. The buffer must be large enough to hold the structures, plus the strings to which their members point.

The order of the services in this array is the reverse of the start order of the services. In other words, the first service in the array is the one that would be started last, and the last service in the array is the one that would be started first.

The maximum size of this array is 64,000 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_MORE_DATA. The pcbBytesNeeded parameter will receive the required size.

cbBufSize
[in] Size of the buffer pointed to by the lpServices parameter, in bytes.
pcbBytesNeeded
[out] Pointer to a variable that receives the number of bytes needed to store the array of service entries. The variable only receives this value if the buffer pointed to by lpServices is too small, indicated by function failure and the ERROR_MORE_DATA error; otherwise, the contents of pcbBytesNeeded are undefined.
lpServicesReturned
[out] Pointer to a variable that receives the number of service entries returned.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

The following error codes may be set by the service control manager. Other error codes may be set by the registry functions that are called by the service control manager.

Return codeDescriptionERROR_ACCESS_DENIEDThe handle does not have the SERVICE_ENUMERATE_DEPENDENTS access right.ERROR_INVALID_HANDLEThe specified handle is invalid.ERROR_INVALID_PARAMETERA parameter that was specified is invalid.ERROR_MORE_DATAThe buffer pointed to by lpServices is not large enough. The function sets the variable pointed to by lpServicesReturned to the actual number of service entries stored into the buffer. The function sets the variable pointed to by pcbBytesNeeded to the number of bytes required to store all of the service entries.

Remarks

The returned services entries are ordered in the reverse order of the start order, with group order taken into account. If you need to stop the dependent services, you can use the order of entries written to the lpServices buffer to stop the dependent services in the proper order.

Example Code

For an example, see Stopping a Service.

Requirements

ClientRequires Windows XP, Windows 2000 Professional, or Windows NT Workstation.ServerRequires Windows Server 2003, Windows 2000 Server, or Windows NT Server.Header

Declared in Winsvc.h; include Windows.h.

Library

Link to Advapi32.lib.

DLLRequires Advapi32.dll. Unicode

Implemented as EnumDependentServicesW (Unicode) and EnumDependentServicesA (ANSI).

原创粉丝点击