Saturday, November 20, 2010

WiX - Installing and uninstalling a windows service

I’m new to wix, and one of its greatest drawbacks for me is out-dated information one can get via blogs and forums.
So here is my take with current (at the time of writing Smile) WiX nightly build of version 3.5:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="">
  <Product Id="9c78f041-c29e-4d80-8d23-e4839e74038c" Name="StansApp" 
           Language="1033" Version=""
           Manufacturer="Standa" UpgradeCode="b1adfc21-927f-470a-ac87-a5019c84a253">
    <Package InstallerVersion="200" Compressed="yes" />
    <Media Id="1" Cabinet="" EmbedCab="yes" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="StansApp">
          <Component Id="ProductComponent" Guid="4810c72f-cb3b-4ef5-b02e-c70a54b8b6ff">
            <File Id='StansAppEXE' Name='WindowsService1.exe' DiskId='1'
                  KeyPath='yes' />
            <ServiceInstall Vital='yes' ErrorControl='ignore' Type='ownProcess' 
                            DisplayName='Stans App Win Service'
                            Description='A proof of concept service' Name='StansWinService' Start='auto' />
            <ServiceControl Id='ControlStansWinService' Remove='both' Name='StansWinService' 
                            Start='install' Stop='both' Wait='yes' />
    <Feature Id="ProductFeature" Title="WinService" Level="1">
      <ComponentRef Id="ProductComponent" />
      <ComponentGroupRef Id="Product.Generated" />

Note usage of Remove=’both’ in the ServiceControl element in order to uninstall the service when both running the installation or uninstallation.

One of the surprising (but quite logical) things to me was to find out that installation via installutil is not actually a good pattern in the world of wix. (or here is another link on it)

Code can be found here

No comments: