views:

311

answers:

2

Hi guys,

I am trying to install a windows service using MSBuild and CCNET. I am using MSBuild Extension pack WindowsService task to install and start the windows service as part of automated build. The script section look like this

<!--install service-->
<MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Install" ServiceName="$(PrServiceName)" ServicePath="$(PrServicePath)" User="$(User)" />

<!--set service to run automatically on restart-->
<MSBuild.ExtensionPack.Computer.WindowsService TaskAction="SetAutomatic" ServiceName="$(PrServiceName)" />

<!--start service-->
<MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Start" ServiceName="$(PrServiceName)" ServicePath="$(PrServicePath)" User="$(User)" />

Now as soon as the the first task runs to install the service, it fails with the following error

E:\Data\cc_temp\Projects\cubic\intranet\pr\pr.build (137,3): error : Install Service failed with code: 'AccessDenied'

I assume this is because the script is running under cruise control service user account which does not have the appropriate permissions for installing a windows service.

I would just like to give minimal permissions to the cruise control user account instead of giving the full administrative rights.

Does anyone out there knows how can i achieve this?

Awaiting Nabeel

A: 

Even after making CC.NET service account member of Administrators group, its still giving the same error.

I have tried installing the service manually via commanline using installutil and it gets installed properly but when msbuild tries to stop it, it gives the same error again.

As part of the cleanup target in my script I am checking if the service exists or not and then stopping it and uninstalling it accordingly. I am using the same MSBuild Extension pack WindowsService task as follows

<!-- Check if the PR Service exists-->
    <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="CheckExists" ServiceName="$(PrServiceName)">
        <Output TaskParameter="Exists" PropertyName="DoesExist" />
    </MSBuild.ExtensionPack.Computer.WindowsService>

    <Message Text="PR Service Exists = $(DoesExist)"/>

    <!-- If exists then stop it and uninstall it-->
    <MSBuild.ExtensionPack.Computer.WindowsService ServiceName="$(PrServiceName)" TaskAction="Stop" Condition=" '$(DoesExist)' == 'true' " />               
    <MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Uninstall" ServiceName="$(PrServiceName)" ServicePath="$(PrServicePath)" Condition=" '$(DoesExist)' == 'true' "/>

    <!-- delete all the file in the folder-->
    <Delete Files="$(PrServiceFolder)\**" />

The first task that checks the service does run, however when it tries to stop the service in the second task, it gives the similar error

Stop Service failed with return code '[2] AccessDenied'

Any idea what could be wrong? I can't seem to find any thing on google either.

Awaiting Nabeel

nabeelfarid
Comeon guys... somebody must have a solution for this out there ??I really need to make this windows service (stop, uninstalled, installed, Start) as part of my automated build. Its a pain doing it manually at the moment...
nabeelfarid
I'm having similar permissions problems with TeamCity and the IIS7 MSBuild tasks. It's runs when I run the MSBuild script on the server with Admin rights but when run under the build agent (for which the user account is a member of the machine's Admin group) it fails with AccessDenied. Would love to know how to solve it!
Mac
@Mac: what MSBuild Task you getting the error on ?
nabeelfarid
I was getting the accessdenied error on MSBuild.ExtensionPack.Web.Iis7Website TaskAction="Stop"I have however found out what was causing the problem. I had added the buildagent service account to the local machine administrator group but it didn't take effect until I restarted the service. I wasted several hours chasing this until I finally remembered to restart the service and since then, no errors.
Mac
A: 

Nabeel you are on the right track, it has to be a permissions issue. We do this all the time in our build using the same tools and it works. Have you checked to see which account the service is running as? and using the same user account to run your cruisecontrol? at least then you would possibly prove/disprove the permissions issue.

Alex
Hi Alex, I was acatulaly using unc path for the *ServicePath* property in the tasks. After changing it to absolute path, everything seems to be working fine.
nabeelfarid