Using WiX to install and start a Windows Service as part of your Add-In install is fairly easy. The only thing you really have to watch out for is the KeyPath value for your service executable; it has to be set to yes, while all other file KeyPaths must be set to no.

Make sure you also use your own GUID values for UpgradeCode and Component ID values.

This code works with the latest WiX 3.0 weekly build.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product
    Name="Windows Home Server Disk Management Add-In"
    Id="*"
    UpgradeCode="{EB6B8302-C06E-4bec-ADAC-932C68A3A98D}"
    Manufacturer="Sam Wood - Tentacle Software"
    Version="1.1.0.0"
    Language="1033">
    <Package
      Manufacturer="Sam Wood - Tentacle Software"
      InstallerVersion="200"
      Languages="1033"
      Compressed="yes" />

    <Media Id="1" Cabinet="WHSDiskManagement.1.1.0.0.cab" EmbedCab="yes" />

    <Property Id="WHSLogo">1</Property>

    <Condition Message="[ProductName] requires Windows Home Server. For more information, please refer to the User Guide.">VersionNT = 502</Condition>

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="PFiles">
        <Directory Id="WHS" Name="Windows Home Server">
          <Component Id="HomeServerConsoleTab.DiskMgt" Guid="{908B7199-DE2A-4dc6-A8D0-27A5AE444FEA}">
            <File Id="HomeServerConsoleTab.DiskMgt.dll" Name="HomeServerConsoleTab.DiskMgt.dll" Source="..\HomeServerConsoleTab.DiskMgt\bin\Release\HomeServerConsoleTab.DiskMgt.dll" Vital="yes" KeyPath="no" DiskId="1"/>
            <File Id="DiskMgt.Common.dll" Name="DiskMgt.Common.dll" Source="..\DiskMgt.Remotable\bin\Release\DiskMgt.Common.dll" Vital="yes" KeyPath="no" DiskId="1"/>
            <File Id="DiskMgt.Service.exe" Name="DiskMgt.Service.exe" Source="..\DiskMgt.Service\bin\Release\DiskMgt.Service.exe" Vital="yes" KeyPath="yes" DiskId="1"/>
            <ServiceInstall
              Id="ServiceInstaller"
              Type="ownProcess"
              Vital="yes"
              Name="DiskManagement"
              DisplayName="Windows Home Server Disk Management"
              Description="Monitoring and management service for Windows Home Server Disk Management Add-In"
              Start="auto"
              Account="LocalSystem" 
              ErrorControl="ignore" 
              Interactive="no"
              >
              <ServiceDependency Id="QSM"/>
              <ServiceDependency Id="pdl"/>
              <ServiceDependency Id="WHSTransportService"/>
            </ServiceInstall>
            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="DiskManagement" Wait="yes" />
		  </Component>
	    </Directory>
	  </Directory>
	</Directory>

	<Feature Id="ProductFeature" Title="WHSDiskManagement" Level="1">
      <ComponentRef Id="HomeServerConsoleTab.DiskMgt" />
	</Feature>
  </Product>
</Wix>

ServiceDependency values are the real names for the services your code depends on. You can find the Service Name by opening services.msc and checking the properties for the specific service.

The ServiceControl node allows you to start and stop services during install and uninstall.

In the example above, I’m controlling a service called DiskManagement (the service I’m installing in the parent ServiceInstall node, but it could be any service). The service is started after the MSI package has been installed, stopped (if it’s started, to allow me to overwrite or delete the service’s files) at the beginning of both install and uninstall operations, and removed at the end of an uninstall operation.

The Service Control Id value is just an identifier that you can use to refer to this specific ServiceControl node in other places in the XML.

If you want to use extended character sets (for localization into different languages, usually) in the various display and description fields, you’ll need to set the xml encoding value and Product Codepage appropriately. I’ve also set the Product Language and Package Languages to German in this example:

<?xml version="1.0" encoding="Windows-1252"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product
    Name="Windows Home Server Datenträger-Verwaltung"
    Id="*"
    UpgradeCode="{EB6B8302-C06E-4bec-ADAC-932C68A3A98D}"
    Codepage="1252"
    Manufacturer="Sam Wood - Tentacle Software"
    Version="1.1.0.0"
    Language="1031">
    <Package
      Manufacturer="Sam Wood - Tentacle Software"
      InstallerVersion="200"
      Languages="1031"
      Compressed="yes" />

There’s some good documentation on the rest of the options (ownProcess, Start type, Account etc.) in the WiX help files that get installed along with the WiX binaries. It’s not the most friendly set of technical docs I’ve seen, but it does give detailed descriptions of the individual configuration elements.

posted on Thursday, January 01, 2009 2:22 PM | Filed Under [ Windows Home Server Development ]

Search

Site Sections

Recent Posts

Archives

Post Categories

WHS Add-In Tutorial

WHS Blogs

WHS Development