Monitors a windows service to reach a specified status.

WaitForServiceStatus(cServiceName | nServiceHandle, nStatus [, nTimeout [, cServer [, cDatabase]]])

Parameters

cServiceName | nServiceHandle

Either the name of the service or a numeric handle returned from the OpenService function.

nStatus

The service status to wait for.

One of the following values.
StatusDescription
SERVICE_STOPPEDThe service is not running.
SERVICE_START_PENDINGThe service is starting.
SERVICE_STOP_PENDINGThe service is stopping.
SERVICE_RUNNINGThe service is running.
SERVICE_CONTINUE_PENDINGThe service continue is pending.
SERVICE_PAUSE_PENDINGThe service pause is pending.
SERVICE_PAUSEDThe service is paused.
nTimeout (optional)

Maximum time in seconds to wait while the service is in not in the requested state.

If you pass 0 as the timout value the function checks the status once and then returns immediately.

If you omit this parameter or pass NULL the timeout is set to the default timeout reported by the service.
See MSDN help for SERVICE_STATUS_PROCESS structure's "dwWaitHint" member.

cServer (optional)

The server name on which the service is running.
See MSDN help for OpenSCManager.

cDatabase (optional)

The database under which the service is registered.
See MSDN help for OpenSCManager.

Return Value

1 if the service is in the requested state within the timeout period, 0 if not.

See Also

Reference

ADependentServices
AServiceConfig
AServices
AServiceStatus
CloseServiceHandle
ContinueService
ControlService
CreateService
OpenService
PauseService
StartService
StopService

Used WinApi functions

QueryServiceStatus
OpenSCManager
OpenService