WiX Toolset

How To: Install a Windows service

To install a Windows service, use the <ServiceInstall> element. Other configuration can be made using the <ServiceControl> element and the <ServiceConfig> element from WixUtilExtension.

Step 1: Install the service

The <ServiceInstall> element contains the basic information about the service to install. This element should be the child of a <Component> element whose key path is a sibling <File> element that specifies the service executable file.

Tip: to specify a system account, such as LocalService or NetworkService, use the prefix NT AUTHORITY. For example, use NT AUTHORITY\LocalService as the Account attribute value to run the service under this account.

Step 2: Configure the service (optional)

Using the <util:ServiceConfig> element from WixUtilExtension, you can configure how the service behaves if it fails. To use it, add WixUtilExtension to your project, add the the util namespace to your WiX authoring, and prefix the element name with the util prefix:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
      <util:ServiceConfig FirstFailureActionType="restart"
                          ThirdFailureActionType="restart" />