14 November, 2014

Building MSI installer with startup registry keys using WIX Toolset

I needed an installer that would:
  • copy 2 specific files to a desired location
  • install one file as a Windows service (anyconnect_SBL.exe)
  • adding a HKLM startup registry key (local machine, not current user startup key) for one of those copied files (clientapp.exe)
For this I use the WIX Toolset http://wixtoolset.org/

Here is the code for build.wxs that worked as needed:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" UpgradeCode="C2918EB3-4E89-4B1E-A3E6-BEBE1A0B0641" Version="1.1.0" Language="1033" Name="Anyconnect SBL service" Manufacturer="dumbajumba">
        <Package InstallerVersion="300" Compressed="yes"/>
        <Media Id="1" Cabinet="myapplication.cab" EmbedCab="yes" />
<!-- Step 1: Define the directory structure -->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="Cisco_Dir" Name="Cisco">
<Directory Id="CiscoAnyConnectSecureMobilityClient_Dir" Name="Cisco AnyConnect Secure Mobility Client">
<Directory Id="SBL_service_dir" Name="SBL_service"/>
</Directory>
</Directory>
</Directory>
</Directory>
<!-- Step 2: Add files to your installer package -->
<DirectoryRef Id="SBL_service_dir">
<Component Id="anyconnect_SBL.exe" Guid="E9663B0F-F740-43C5-AFAC-D5D1AF0AB1B8">
<File Id="anyconnect_SBL.exe" Name="anyconnect_SBL.exe" Source="anyconnect_SBL.exe" KeyPath="yes" Checksum="no"/>
<ServiceInstall Id="anyconnect_SBL.exe" DisplayName="anyconnect_SBL" Name="anyconnect_SBL.exe" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" />
<ServiceControl Id="anyconnect_SBL.exe" Name="anyconnect_SBL.exe" Start="install" Stop="uninstall" Remove="uninstall" />
</Component>
<Component Id="clientapp.exe" Guid="3C26A063-DEAB-416A-A568-8483A7764026">
<File Id="clientapp.exe" Name="clientapp.exe" Source="clientapp.exe" KeyPath="yes" Checksum="no"/>
<RegistryKey
Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Run">
<RegistryValue Id="clientapp" Name="clientapp" Value="[SBL_service_dir]clientapp.exe" Type="string" />
</RegistryKey>
</Component>
</DirectoryRef>
<!-- Step 3: Tell WiX to install the files -->
<Feature Id="MainApplication" Title="Main Application" Level="1">
<ComponentRef Id="anyconnect_SBL.exe" />
<ComponentRef Id="clientapp.exe" />
</Feature>
</Product>
</Wix>

No comments:

Post a Comment