Thursday, June 20, 2013

WiX: how to install and start Windows service running under LocalSystem account

Tip 1: Separate service under own <Component> tag.

Tip 2: Don't forget to include this <Component> into <Feature> tag.

Tip 3: Mark service executable <File> tag with KeyPath='yes' attribute.

Tip 4: If you want to configure user access rights for this service, include <util:PermissionEx> tag.

Tip 4.1: Don't forget to include "xmlns:util" namespace into <Wix> tag.

Tip 4.2: Don't forget to add "-ext WixUtilExtension" parameter to "candle" and "light" command lines.

Tip 5: User needs to run installer under administrative account to be able to install service under LocalSystem account.

Real example
  • installs and starts service on installation;
  • stops and removes service on uninstallation.


<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns=''

    <Product ... >

        <Package ... />

        <Directory Id='TARGETDIR' Name='SourceDir'>

            <Directory Id='INSTALLDIR' Name='MyApplication'>
                    <Component Id='MyService' Guid='2575CFDC-5F26-4D81-BCD3-81F4209B7CAD'>
                        <File Id='MyService.exe' Name='MyService.exe' Source='MyService.exe' DiskId='1' KeyPath='yes' />
                        <ServiceInstall Id="MyService" Type="ownProcess" Name="MyService" DisplayName="MyService display name"
                                Description="MyService description" Start="auto" Account="LocalSystem" ErrorControl="normal">
                            <util:PermissionEx  User="Everyone" ServicePauseContinue="yes" ServiceQueryStatus="yes"
                                    ServiceStart="yes" ServiceStop="yes" ServiceUserDefinedControl="yes" />                                
                        <ServiceControl Id="MyService" Start="install" Stop="both" Remove="both" Name="MyService" Wait="no" />                                


  <Feature Id='Complete' Level='1'>
   <ComponentRef Id='MyService' />




candle.exe myapplication.wxs -ext WixUtilExtension
light.exe myapplication.wixobj -ext WixUIExtension -ext WixUtilExtension

No comments:

Post a Comment