Skip to main content
Version: v3

Adding a Custom Action

This example shows how to author a binary custom action called "FooAction". A common example is a dll custom action that launches notepad.exe or some other application as part of their install. Before you start, you will need a sample dll that has an entrypoint called "FooEntryPoint". This sample assumes you have already reviewed the Creating a Skeleton Extension topic.

Step 1: Create a Fragment

You could directly reference the custom action in the same source file as the product definition. However, that will not enable the same custom action to be used elsewhere. So rather than putting the custom action definition in the same source file, let's exercise a little modularity and create a new source file to define the custom action called "ca.wxs".

<?xml version='1.0'?>
<Wix xmlns=''>
<b><span class="style1"> &lt;Fragment&gt;</span>
<span class="style1"> &lt;CustomAction Id='FooAction' BinaryKey='FooBinary' DllEntry='FooEntryPoint' Execute='immediate'</span>
<span class="style1"> Return='check'/&gt;</span>

<span class="style1"> &lt;Binary Id='FooBinary' SourceFile='foo.dll'/&gt;</span>
<span class="style1"> &lt;/Fragment&gt;</span></b>

Okay, that's it. We're done with editing the "ca.wxs" source file. That little bit of code should compile but it will not link. Remember linking requires that you have an entry section. A <Fragment/> alone is not an entry section. Go to the next step to link the source file.

Step 2: Add the custom action

We would need to link this source file along with a source file that contained <Product/> or <Module/> to successfully complete.

&lt;?xml version='1.0'?&gt;
&lt;Wix xmlns=''&gt;
&lt;Product Id='PUT-GUID-HERE' Name='Test Package' Language='1033'
Version='' Manufacturer='.NET Foundation'&gt;
&lt;Package Description='My first Windows Installer package'
Comments='This is my first attempt at creating a Windows Installer database'
Manufacturer='.NET Foundation' InstallerVersion='200' Compressed='yes' /&gt;

&lt;Media Id='1' Cabinet='' EmbedCab='yes' /&gt;

&lt;Directory Id='TARGETDIR' Name='SourceDir'&gt;
&lt;Directory Id='ProgramFilesFolder' Name='PFiles'&gt;
&lt;Directory Id='MyDir' Name='Test Program'&gt;
&lt;Component Id='MyComponent' Guid='PUT-GUID-HERE'&gt;
&lt;File Id='readme' Name='readme.txt' DiskId='1' Source='readme.txt' /&gt;

&lt;Merge Id='MyModule' Language='1033' SourceFile='module.msm' DiskId='1' /&gt;

&lt;Feature Id='MyFeature' Title='My 1st Feature' Level='1'&gt;
&lt;ComponentRef Id='MyComponent' /&gt;
&lt;MergeRef Id='MyModule' /&gt;
<span class="style1"> &lt;InstallExecuteSequence&gt;</span>
<span class="style1"> &lt;Custom Action='FooAction' After='InstallFiles'/&gt;</span>
<span class="style1"> &lt;/InstallExecuteSequence&gt;</span></b>

Those three lines are all you need to add to your Windows Installer package source file to call the "FooAction" CustomAction. Now that we have two files to link together our call to light.exe gets a little more complicated. Here are the compile, link, and installation steps.

C:\test&gt; <span class="style2">candle product.wxs ca.wxs</span>

C:\test&gt; <span class="style2">light product.wixobj ca.wixobj &ndash;out product.msi</span>

C:\test&gt; <span class="style2">msiexec /i product.msi</span>

Now as part of your installation, whatever "FooAction" is supposed to perform, you should see happen after the InstallFiles action.