Skip to content

Service_GetState

Gets the current state of the specified service.

Service_GetState(sServiceName) As Boolean

Name of the service. Use the service name, for example Spooler, not the display name.

Result will be stored in gsValue, as Windows reports it: Running, Stopped, Paused, Start Pending, Stop Pending, Continue Pending, Pause Pending or Unknown.

Running, Stopped and Paused match the Service Controller Status constants SCS_Running, SCS_Stopped and SCS_Paused. The pending states contain a space, so compare them with the text, for example "Start Pending", not with the SCS constants.

The function returns False if the service doesn’t exist.

If bStatus Then bStatus = Service_GetState("Service")
If bStatus Then bStatus = Job_WriteLog("Custom", "gsValue: " & gsValue, bStatus, True)

Scripting Guidelines

Service_Exist Service_SetLogonInformations Constants Package Property Variables