WindowsService Class

MSBuild Extension Pack

WindowsService Class MSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

CheckExists (Required: ServiceName Optional: MachineName, RemoteUser, RemoteUserPassword Output: Exists)

Delete (Required: ServiceName Optional: MachineName)

Disable (Required: ServiceName Optional: MachineName)

Install (Required: ServiceName, ServicePath, UserOptional: Force, StartupType, CommandLineArguments, Description, ServiceDependencies, ServiceDisplayName, MachineName, RemoteUser, RemoteUserPassword)

Restart (Required: ServiceName Optional: MachineName). Any running directly dependent services will be restarted too.

SetAutomatic (Required: ServiceName Optional: MachineName)

SetManual (Required: ServiceName Optional: MachineName)

Start (Required: ServiceName or Services Optional: MachineName, RetryAttempts)

Stop (Required: ServiceName or Services Optional: MachineName, RetryAttempts)

Uninstall (Required: ServicePath Optional: MachineName, RemoteUser, RemoteUserPassword)

UpdateIdentity (Required: ServiceName, User, Password Optional: MachineName)

Remote Execution Support: Yes

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.ComputerWindowsService

Namespace: MSBuild.ExtensionPack.Computer
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The WindowsService type exposes the following members.

Constructors

  NameDescription
Public methodWindowsService
Top
Properties

  NameDescription
Public propertyCommandLineArguments
Sets the command line arguments to be passed to the service.
Public propertyDescription
Sets the service description
Public propertyExists
Gets whether the service exists
Public propertyForce
Sets a value indicating whether to delete a service if it already exists when calling Install
Public propertyPassword
Sets user password
Public propertyRemoteUser
Sets the user to impersonate on remote server.
Public propertyRemoteUserPassword
Sets the password for the user to impersonate on remote server.
Public propertyRetryAttempts
Sets the number of times to attempt Starting / Stopping a service. Default is 60.
Public propertyServiceDependencies
Sets the services upon which the installed service depends.
Public propertyServiceDisplayName
The Display Name of the service. Defaults to ServiceName.
Public propertyServiceName
The Name of the service. Note, this is the 'Service Name' as displayed in services.msc, NOT the 'Display Name'
Public propertyServicePath
Sets the path of the service executable
Public propertyServices
Sets the collection of Services to target in parallel. See TaskAction parameters for which TaskActions support this.
Public propertyStartupType
Sets the Startup Type of the service.
Public propertyUser
Sets the user.
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
        <User>serviceAcct</User>
        <Password>P2ssw0rd</Password>
        <RemoteMachine>VSTS2008</RemoteMachine>
        <RemoteUser>vsts2008\tfssetup</RemoteUser>
        <RemoteUserPassword>1Setuptfs</RemoteUserPassword>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <!-- check whether a service exists (this should return true in most cases) -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="CheckExists" ServiceName="Schedule">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Computer.WindowsService>
        <Message Text="Schedule service exists: $(DoesExist)"/>
        <!-- check whether another service exists (this should return false)-->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="CheckExists" ServiceName="ThisServiceShouldNotExist">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Computer.WindowsService>
        <Message Text="ThisServiceShouldNotExist service exists: $(DoesExist)"/>
        <!-- Check whether a service exists on a Remote Machine(this should return true in most cases) -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="CheckExists" ServiceName="Schedule" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Computer.WindowsService>
        <Message Text="Schedule service exists on '$(RemoteMachine)': $(DoesExist)"/>
        <!-- Start a service -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Start" ServiceName="MSSQLSERVER"/>
        <!-- Start a service on a Remote Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Start" ServiceName="BITS" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)" />
        <!-- Stop a service -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Stop" ServiceName="MSSQLSERVER"/>
        <!-- Stop a service on a Remote Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Stop" ServiceName="BITS" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)"/>
        <!-- Uninstall a service on the Local Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Uninstall" ServiceName="__TestService1" ServicePath="c:\WINDOWS\system32\taskmgr.exe" />
        <!-- Uninstall a service on a Remote Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Uninstall" ServiceName="__TestService1" ServicePath="c:\WINDOWS\system32\taskmgr.exe" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)" />
        <!-- Install a service on the Local machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Install" ServiceName="__TestService1" User="$(User)" Password="$(password)" ServicePath="c:\WINDOWS\system32\taskmgr.exe" />
        <!-- Install a service on a Remote Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Install" ServiceName="__TestService1" User="$(User)" Password="$(password)" ServicePath="c:\WINDOWS\system32\taskmgr.exe" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)" />
        <!-- Disable a service -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Disable" ServiceName="__TestService1"/>
        <!-- Disable a service on a Remote Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Disable" ServiceName="__TestService1" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)"/>
        <!-- Set a service to start automatically on system startup-->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="SetAutomatic" ServiceName="__TestService1"/>
        <!-- Set a service to start automatically on system startup on a Remote Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="SetAutomatic" ServiceName="__TestService1" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)"/>
        <!-- Set a service to start manually -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="SetManual" ServiceName="__TestService1"/>
        <!-- Set a service to start manually on a Remote Machine -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="SetManual" ServiceName="__TestService1" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)"/>
        <!-- Update the Identity that the service runs in -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="UpdateIdentity" ServiceName="__TestService1" User="$(User)" Password="$(Password)"/>
        <!-- Update the Identity that the service on a Remote Machine runs in -->
        <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="UpdateIdentity" ServiceName="__TestService1" User="$(User)" Password="$(Password)" RemoteUser="$(RemoteUser)" RemoteUserPassword="$(RemoteUserPassword)" MachineName="$(RemoteMachine)"/>
    </Target>
</Project>
See Also

Reference