I have the following declaration of my service:
The ServiceInstall Account must be fully qualified, as such:
<ServiceInstall ... Account="NT AUTHORITY\LocalService" />
It can fail if only specified like this:
<ServiceInstall ... Account="LocalService" />
Probably you have to set the permission for the your service, something like that:
<ServiceInstall Id="YourServiceID" Name="ServiceName" DisplayName="DisplayName"
Description="Description"
Arguments="service start arguments"
Start="demand" Type="ownProcess" ErrorControl="ignore">
<util:PermissionEx User="Authenticated Users"
ServiceStart="yes"
ServiceStop="yes"
ServicePauseContinue="yes"
ServiceInterrogate="yes"
ServiceChangeConfig="yes"
ServiceEnumerateDependents="yes"
ServiceQueryConfig="yes"
ServiceQueryStatus="yes"
ServiceUserDefinedControl="yes" />
</ServiceInstall>
<ServiceControl Id="SvcControlID" Name="ServiceName" Stop="both"
Remove="uninstall" Wait="yes" />
and dont forget to include the UtilExtension: xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
There is another way (but not recomended :) You could try to install it using custom actions:
<Property Id="CMD" Secure="yes"><![CDATA[cmd.exe]]></Property>
<CustomAction Id="InstallService32" Property="CMD" ExeCommand="/c ""[INSTALLLOCATION][ServiceName]" /i [ServiceName] "/c [SVC_CONFIG]""" Execute="deferred" Impersonate="no" Return="ignore" />
<CustomAction Id="InstallService64" Property="CMD" ExeCommand="/c ""[INSTALLLOCATION][ServiceName]" /i [ServiceName] "/c [SVC_CONFIG]""" Execute="deferred" Impersonate="no" Return="ignore" />
<CustomAction Id="StartService" Property="CMD" ExeCommand="/c "NET START [ServiceName]"" Execute="deferred" Impersonate="no" Return="ignore" />
<CustomAction Id="StopService" Property="CMD" ExeCommand="/c "NET STOP [ServiceName]"" Execute="deferred" Impersonate="no" Return="ignore" />
The problem with this code is that you need to have the install location without the white spaces (I had a problem with white spaces and could not manage to solve it, probably you'll be more lucky).
It should work without the WiX util extension. Here is my complete test installer. Create your own test project and copy and past my installer into your .wxs file. Then replace the File, ServiceInstall and ServiceControl paths and names with your own service. If you still get the same error message, could it be that you don't actually have the privileges to do the install on your machine?
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="TestServiceInstaller" Language="1033" Version="1.0.0.0" Manufacturer="test" UpgradeCode="d2b63c57-ca50-4f6a-8019-e826cac3d788">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="TestServiceInstaller" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="TestServiceInstaller" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="TestService.exe" Guid="196BB5E5-F157-4CA2-B740-0A68E1539B7C">
<File Id="TestService.exe" Source="C:\Users\bryan.johnston\Documents\visual studio 2010\Projects\TestService\TestService\bin\Debug\TestService.exe" KeyPath="yes" />
<ServiceInstall Id="TestService.exe" Name="TestService.exe" Account="LocalSystem" Arguments="-start" Start="auto" Interactive="yes" Type="ownProcess" Vital="yes" ErrorControl="critical" />
<ServiceControl Id="TestService.exe" Name="TestService.exe" Stop="both" Start="install" Remove="uninstall" Wait="no" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
The error message is misleading. You will get that error message whenever the service fails to start, but it may not have anything to do with permissions.
Open a visual studio command prompt and manually install it:
installutil <name_of_service.exe>
If your service fails, it is an issue with your service and not the installer.
This can also occur when the services file name (in my case an .exe) is wrong. I managed to work aroud by putting the correct file (the executable) to the first place in the file list sth like:
The name of the service file name can be viewed in the Event viewer - Event Id of service installation is 7045
Regards Thomas
After a lot of failed attempts, in my case all goes well after removing Account="LocalSystem"
in the ServiceInstall tag (by default Windows install the service as LocalSystem)