Loren Halvorson's Blog

If your only tool is a hammer...

Adding UI to your WiX installer

This is part two of my posts on features I recently discovered in WiX. Adding a UI to your installer is extremely simple now. Far easier than the way I used to do it. This technique is mentioned in the excellent WiX tutorial. It is also being used by the Votive install which you can look at in the WiX source on SourceForge.

Here is a sample similar to my previous one that demonstrated XmlFile but this time just adds a UI. If you are interested in seeing this work it only takes a couple minutes to try, get a hold of the latest WiX binaries from SourceForge and follow these steps.

This is just any old file we want to install, save it to a directory.

--sample.config--

<configuration>
  <appSettings>
    <add key="ServiceLocation" value="localhost"/>
  </appSettings>
</configuration>

Then you should create a file named License.rtf using Word or some other RTF editor in the same directory.

Here is the WiX script that includes the UIRef element, save it to the same directory. I've highlighted the new parts.

--wixsetup.wxs--

<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi">

  <Product Id="88DC12AD-74D8-415a-AFE7-83C1BE05A3EB" Name="WixUI Sample" Language="1033" Version="1.0.0" Manufacturer="WixUI">
    <Package Id="????????-????-????-????-????????????" Description="Sample showing WixUI used in a WiX setup." Comments="Sample showing WixUI used in a WiX setup." InstallerVersion="200" Compressed="yes" />

    <Media Id="1" Cabinet="Product.cab" EmbedCab="yes" />
   
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="WiXSampl" LongName="WixUI WiX Sample">
            <Component Id="ProgramComponent" Guid="3D62CA0A-DE38-4687-95BE-1B200670E35A">
              <File Id="_F86C7B1F61C44480BEFA68A2D045D7BB" Name="SAMPLE.CON" LongName="sample.config" src="sample.config" Vital="yes" DiskId="1"/>
              <File Id="_F86C7B1F61C44480BEFA68A2D045D7BC" Name="License.rtf" LongName="license.rtf" src="license.rtf" Vital="yes" DiskId="1"/>
            </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="Complete" Title="WixUI Sample" Level="1">
      <ComponentRef Id="ProgramComponent" />
    </Feature>
   
    <UIRef Id="WixUI" />

  </Product>
</Wix>


Then run the following batch file also in that same directory to compile the MSI (fix up wix_home to where you unzipped WiX).

--CreateSetup.bat--

@set wix_home=C:\wix
"%wix_home%\candle.exe" wixsetup.wxs
"%wix_home%\light.exe" -out wixsetup.msi wixsetup.wixobj "%wix_home%\ca\wixca.wixlib" "%wix_home%\ui\wixui_featuretree.wixlib"

Viola, you now have a UI. Run wixsetup.msi to see it.

The next obvious question is how do you modify this UI by inserting additional wizard pages, or removing ones that are there, and I apologize, but I haven't learned how to do this yet. But this is a good start. If anyone else has a "recipe" on how to add a new custom page to any of the WixUI flavors (WixUI_Mondo, WixUI_FeatureTree, or WixUI_Minimal), please let me know.

Comments

Peter Jeffery said:

I customised the UI from the WixUI_Mondo by using it to generate my MSI, then using dark to disassemble back to a WXS file and then extracting the UI element out of it and working on that. It doesn't seem the best way to work, but it certainly seems like a lot less typing than working from scratch.
# October 25, 2005 12:11 PM