How to Implement Windows Installer Xml(WiX) Customization (Custom Action)

What is Custom Action?

The Windows Installer provides many built-in actions for performing the installation process. Standard actions are sufficient to execute an installation in most cases. However, there are situations where the developer of an installation package finds it necessary to write a custom action. Custom action is a way to extend functionality of Windows« Installer. A developer can write customization code in a dll or script(like the sample below) for their specific requirements and tell Windows Installer to invoke the code at certain points during setup.

Create an xml file: product.wxs (copied from WiX.chm) as below. This WiX file will create an MSI file that copies readme.txt into "%sysdrv%/program files/test program/".

<?xml version='1.0'?>
<WiX xmlns='http://schemas.microsoft.com/WiX/2003/01/wi'>
   <Product Id='12345678-1234-1234-1234-123456789012' Name='Test Package' Language='1033'
            Version='1.0.0.0' Manufacturer='Microsoft Corporation'>
      <Package Id='12345678-1234-1234-1234-123456789012'
                Description='My first Windows Installer package'
                Comments='This is my first attempt at creating a Windows Installer database'
                Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' />
 
      <Media Id='1' Cabinet='product.cab' EmbedCab='yes' />
 
      <Directory Id='TARGETDIR' Name='SourceDir'>
         <Directory Id='ProgramFilesFolder' Name='PFiles'>
            <Directory Id='MyDir' Name='TestProg' LongName='Test Program'>
               <Component Id='MyComponent' Guid='12345678-1234-1234-1234-123456789012'>
                  <File Id='readme' Name='readme.txt' DiskId='1' src='readme.txt' />
               </Component>
            </Directory>
         </Directory>
      </Directory>
 
      <Feature Id='MyFeature' Title='My 1st Feature' Level='1'>
         <ComponentRef Id='MyComponent' />
      </Feature>
   </Product>
</WiX>

Compile WiX file:

    c:\WiX\candle product.wxs

Link WiXObj into MSI:

    c:\WiX\light product.WiXobj 

Test your first MSI:

    c:\WiX\msiexec /i product.msi

Create a customization VBS code: Customization.vbs

    function Hello
       MsgBox "Hello from customization VBS!"
    end function

By using VBS customization code you can achieve a lot of things, like creating an IIS VDIR, acling some resources, setting COM+, etc. Now you need to modify product.wxs to invoke the customization.vbs as below:

<?xml version='1.0'?>
<WiX xmlns='http://schemas.microsoft.com/WiX/2003/01/wi'>
   <Product Id='12345678-1234-1234-1234-123456789012' Name='Test Package' Language='1033'
            Version='1.0.0.0' Manufacturer='Microsoft Corporation'>
      <Package Id='12345678-1234-1234-1234-123456789012'
                Description='My first Windows Installer package'
                Comments='This is my first attempt at creating a Windows Installer database'
                Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' />
 
      <Media Id='1' Cabinet='product.cab' EmbedCab='yes' />
 
      <Directory Id='TARGETDIR' Name='SourceDir'>
         <Directory Id='ProgramFilesFolder' Name='PFiles'>
            <Directory Id='MyDir' Name='TestProg' LongName='Test Program'>
               <Component Id='MyComponent' Guid='12345678-1234-1234-1234-123456789012'>
                  <File Id='readme' Name='readme.txt' DiskId='1' src='readme.txt' />
               </Component>
            </Directory>
         </Directory>
      </Directory>
 
      <Feature Id='MyFeature' Title='My 1st Feature' Level='1'>
         <ComponentRef Id='MyComponent' />
      </Feature>
<InstallExecuteSequence> <Custom Action="test" Sequence='1'/> </InstallExecuteSequence> <Binary Id='Customization.vbs' src='Customization.vbs'/> <CustomAction Id='test' BinaryKey='Customization.vbs' VBScriptCall='Hello' Return='check'/> </Product> </WiX>

We add a Binary node to specify the Binary data used for CustomAction elements, and added CustomAction node to specify a custom action to be added to the MSI CustomAction table. Various combinations of the attributes for this element correspond to different custom action types. For more information about custom actions see the MSDN documentation http://msdn2.microsoft.com/en-us/library/aa372048.aspx for a "Summary List of All Custom Action Types".

Finally we add a Custom node to sequence a custom action. Since Custom must be a child node of AdminExecuteSequence, AdminUISequence, AdvertiseExecuteSequence, InstallExecuteSequence, InstallUISequence, thus we add a InstallExecuteSequence.

Compile again:

    c:\WiX\candle product.wxs

Link again:

    c:\WiX\light product.WiXobj 

Test your MSI again: now you will see a pop window coming from your WiX customization(CustomAction) code.

    c:\WiX\msiexec /i product.msi

Similiarly, you can use custom actions to create/update or start/stop your COM+ applications.

    Function ResetCOMPlus
        Set objApplicationsAdmin = CreateObject("COMAdmin.COMAdminCatalog")
        objApplicationsAdmin.ShutdownApplication "OrderCheck"  
    End function    

See also

  • Introduction to the Windows Installer XML(WiX) Toolset
  • MSI basics
  • WiX Tutorial - Steps to Create an MSI with Windows Installer XML(WiX)
  • How to Install a COM DLL with Windows Installer XML(WiX)
  • How to Add a License Agreement UI to Windows Installer XML(WiX)
  • How to Add Customization Code CustomAction to Windows Installer XML(WiX)
  • How to Reset Windows Service with Windows Installer XML(WiX)
  • How to Troubleshoot MSI Installation
  • How to Pass Parameters to the Customization Code(CustomAction)
  • How to Log Tracing Infomation to the Calling MSI from CustomAction
  • How to Invoke InstallUtil.exe to Call Your Managed Installer Class
  • How to Create a Website and Virtual Directory with Windows Installer XML(WiX)
  • How to Install Files to an Arbitrary Location Outside "Program Files"
  • How to Read Configuration Parameters from Xml File
  • How to Use Environmental Variables and WiX Preprocessor
  • Download WiXSharp



  • THIS POST IS PROVIDED "AS-IS" WITH NO WARRANTIES AND CONFERS NO RIGHTS. Build time: Sun 01/27/2008 . ©2007 Dalun Software. All rights reserved. Back to Article List