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".
<b><span class="style1"> <Fragment></span>
<span class="style1"> <CustomAction Id='FooAction' BinaryKey='FooBinary' DllEntry='FooEntryPoint' Execute='immediate'</span>
<span class="style1"> Return='check'/></span>
<span class="style1"> <Binary Id='FooBinary' SourceFile='foo.dll'/></span>
<span class="style1"> </Fragment></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.
<Product Id='PUT-GUID-HERE' Name='Test Package' Language='1033'
Version='184.108.40.206' Manufacturer='.NET Foundation'>
<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' />
<Media Id='1' Cabinet='product.cab' EmbedCab='yes' />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='MyDir' Name='Test Program'>
<Component Id='MyComponent' Guid='PUT-GUID-HERE'>
<File Id='readme' Name='readme.txt' DiskId='1' Source='readme.txt' />
<Merge Id='MyModule' Language='1033' SourceFile='module.msm' DiskId='1' />
<Feature Id='MyFeature' Title='My 1st Feature' Level='1'>
<ComponentRef Id='MyComponent' />
<MergeRef Id='MyModule' />
<span class="style1"> <InstallExecuteSequence></span>
<span class="style1"> <Custom Action='FooAction' After='InstallFiles'/></span>
<span class="style1"> </InstallExecuteSequence></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> <span class="style2">candle product.wxs ca.wxs</span>
C:\test> <span class="style2">light product.wixobj ca.wixobj –out product.msi</span>
C:\test> <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.