$service function

$service(name)

The $service function returns the status of the passed-in service name. If name is empty, refers to a non-existing service, or the service cannot be accessed, the result is 0. The returned service status is one of the following:

Status Win32 API constant Meaning
0 n/a Service does not exist or cannot be accessed.
1 SERVICE_STOPPED Service exists, but is not currently active.
2 SERVICE_START_PENDING Service is in the process of being started.
3 SERVICE_STOP_PENDING Service is in the progress of being stopped.
4 SERVICE_RUNNING Service is running normally.
5 SERVICE_CONTINUE_PENDING Service is in transition from paused to running.
6 SERVICE_PAUSE_PENDING Service is in transition from running to paused.
7 SERVICE_PAUSED Service is paused (suspended).

Parameters

All parameters may contain symbolic references; these are resolved before the function is applied. See Examples below.

name
Name of the service to test. This must be the internal name, not the display name. For example, use BITS and not "Background Intelligent Transfer Service" to query the status of the BITS service.

Examples

Here are some usage examples for this function:

<$service(BITS)>
Returns a value from 0 to 7 indicating whether the BITS service (Background Intelligent Transfer Service) is running.
<$service(MyService)>
Returns a value from 0 to 7 indicating whether the MyService service is running. This can be used to control additional installation actions. In simple cases, a return value of 0 (zero) can be used as False in conditional expressions and any nonzero value as True.

See also

Service, Service Action