ServiceFunctions.

GetStatus(string, string) Method

Summary

Gets the status of the specified service.
Assembly
NAnt.Contrib.dll
Namespace
NAnt.Contrib.Functions
Containing Type
ServiceFunctions

Syntax

[Function("get-status")]
public static ServiceControllerStatus GetStatus(string service, string machineName)

Examples

Displays a warning if the Alerter service is stopping on SV-ARD-EAI1.

    <if test="${service::get-status('Alerter', 'SV-ARD-EAI1') == 'StopPending'}">
    <echo level="Warning">The Alerter service is stopping.</echo>
</if>

The "deploy-web-application" target is only executed if IIS is running on the local computer.

    <target name="deploy" depends="deploy-sql-scripts, deploy-web-application" />

<target name="deploy-sql-scripts">
    ...
</target>

<target name="deploy-web-application" if="$(service::get-status('World Wide Web Publishing', '.') == 4)}">
    ...
</target>

Remarks

For the machineName parameter, you can use "." or a zero-length string to represent the local computer.

The value returned by NAnt.Contrib.Functions.ServiceFunctions.GetStatus(System.String,System.String) can be compared to either a corresponding enum field name or the underlying integral value.

Attributes

Type Description
Function

Parameters

Name Type Description
service string The short name that identifies the service to the system.
machineName string The computer on which the service resides.

Return Value

Type Description
ServiceControllerStatus One of the System.ServiceProcess.ServiceControllerStatus values that indicates whether the service is running, stopped, or paused, or whether a start, stop, pause, or continue command is pending.