This project is read-only.

Deploy windows service to local machine

Sep 18, 2012 at 2:51 AM
Edited Sep 18, 2012 at 2:55 AM

I'm new to the extension pack and I'm using it to build a deploy task to install & start a service on the local machine.  The service installs, and is set to 'automatic start' but the service is unable to start.  

The error message I get is "Error 1053: The service did not respond to the start or control request in a timely fashion"

In the event logs I see "A timeout was reached (30000 milliseconds) while waiting for the MyService service to connect."

I see this behavior from the build task and if I open the services snap-in and click 'start'.  The failure occurs under 1s - not the 3s described in the event log.

Here is the task defined in my .build file:


<Target Name="Install-Local-ServiceHost">       
    <ServiceFiles  Include="$(SolutionDir)\src\runtimes\service\bin\$(configuration)\*.*" />

  <Copy SourceFiles="@(ServiceFiles)" DestinationFolder="$(installDir)" />
  <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Install" ServiceName="$(serviceName)" ServiceDisplayName="$(serviceName)" User="$(username)" Password="$(password)" ServicePath="$(installDir)\Service.exe"/>
  <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="SetAutomatic" ServiceName="$(serviceName)"/>
  <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Start" ServiceName="$(serviceName)" />



Here is how it gets called: 

msbuild /t:Install-Local-ServiceHost /p:installDir="d:\projects\app\deployment\debug\service" /p:username=user /p:password=myPassword /p:ServiceName=MyService

I know my code isn't even getting executed, as the first thing my service does is set up logging, which doesn't happen when I attempt to start the service.  

Ideally I would be able to create a single build task that works for both local & remote deployments, but I'd like to get local working first.

Any help would be appreciated,



Sep 18, 2012 at 1:28 PM

Hi Jason

A few things...

1. Does the Account have permission to run as a service? if you should run something like this

        <MSBuild.ExtensionPack.Computer.ActiveDirectory TaskAction="GrantPrivilege" User="$(UserName)" Privilege="SeServiceLogonRight"/>

2. A difference between this way of installing the service and using installutil is that installer code is not run in the service so you will not get the default eventlog source created. I suspect your users is not an admin and what's happening is it wants to write an event to the event log using its name as a source, but the source does not exist and it cant create the source because it's not an admin. To get around this you could change where you service logs to or create the event source using the registry task.

I'll see if I can make this process a little less complex in the next release.

Hope that helps


Sep 18, 2012 at 3:24 PM
Edited Sep 18, 2012 at 4:39 PM

Hi Mike,

Thanks for the help, it turned out to be a silly misunderstanding on my part, the value of the parameter ServiceName didn't match the name of the service class, once I got those lined up everything worked as expected.

How tough would it be to add support for service instances to the install task? I find that I sometimes need to install the same service side-by-side on the same machine, and it doesn't look like I can do that with the extension pack as it now stands.  

Another question is how to install the service as a LocalSystem or NetworkService account?



Marked as answer by mikeFourie on 5/26/2014 at 10:03 AM