The main page for the series is here.
Introduction
Although standard actions are sufficient to execute an installation in most cases, custom actions enable the author of an installation package to extend the capabilities of standard actions by including executables, dynamic-link libraries, and script.
Important: Custom actions cannot be used in the sequence tables used for advertisement: AdvtUISequence and AdvtExecuteSequence tables.
Custom action types
Deprecated concurrent installation actions
Concurrent Installations, also called Nested Installations, is a deprecated feature of the Windows Installer. Do not use concurrent installations to install products that are intended to be released to the public.
Execution scheduling options
Because a custom action can be scheduled in both the UI and execute sequence tables, and can be executed either in the service or client process, a custom action can potentially execute multiple times.
This table describes the bit flags in the Type column of the CustomAction table and their meaning:
Hidden Target option
Use the following option flags to specify that the installer not write the value entered into the Target field of the CustomAction table into the log.
In-script execution options
You can use the following option flags to specify the in-script execution of custom actions. These options copy the action code into the execution, rollback, or commit script.
Note that the msidbCustomActionTypeInScript must be included with each of these options.
Return processing options
The flags are used to specify that the main and custom action threads run synchronously (Windows Installer waits for the custom action thread to complete before resuming the main installation thread), or asynchronously (Windows Installer runs the custom action simultaneously while the main installation continues).
Custom Action return values
The following error codes can be returned from the DLL custom action. For EXE custom actions zero value means success and any other value indicates an error.
Scripting Custom Action return values
Scripting custom actions must return one of the following return codes:
Custom Action Type 1
Calls a dynamic link library written in C/C++ which is stored in the Binary table.
The Source column in the CustomAction table contains the key to the record in the Binary table.
The DLL is called through the entry point named in the Target column of the CustomAction table.
All return processing, execution scheduling, and in-script execution options apply.
Entry point to the custom action receives the handle to the installation session. During execution of deferred custom action, session may no longer exist. To get the value of properties use CustomActionData property.
Here is how to add Type 1 custom action in Wix:
<Binary Id="MyCA" SourceFile="MyCA.dll"/>
<CustomAction Id="DoSomething"
BinaryKey="MyCA"
DllEntry="DoFunction"
Execute="deferred"
Return="check"
HideTarget="no"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="DoSomething" Before="InstallFinalize" />
</InstallExecuteSequence>
First, we add MyCA.dll to the Binary table.
We also add a custom action of Type 1 to the CustomAction table. BinaryKey attribute points to the <Binary> element with the custom action dll. DllEntry attribute specifies the name of the entry point function in the dll.
The last thing to do is to schedule our custom action in all required sequence tables.
Custom Action Type 2
Calls an executable stored in the Binary table.
The Target column in the CustomAction table contains the command line string for the executable.
Here is how to add Type 2 custom action in Wix:
<Binary Id="MyCA" SourceFile="MyCA.exe"/>
ExeCommand="-switch"
First, we add MyCA.exe to the Binary table.
We also add a custom action of Type 2 to the CustomAction table. BinaryKey attribute points to the <Binary> element with the custom action dll. ExeCommand attribute specifies the command line string for the executable.
Custom Action Type 5
Calls the JScript custom action stored in the Binary table.
The Target column in the CustomAction table contains the optional script function to execute.
All scripting custom actions require the installation of the Session object. During execution of deferred custom action, Session object may no longer exist. To get the value of properties use CustomActionData property.
Here is how to add Type 5 custom action in Wix:
<Binary Id="MyCA" SourceFile="MyCA.js"/>
JScriptCall="Main"
First, we add MyCA.js to the Binary table.
We also add a custom action of Type 5 to the CustomAction table. BinaryKey attribute points to the <Binary> element with the custom action dll. JScriptCall attribute specifies the script function to execute.
Custom Action Type 6
Calls the VBScript custom action stored in the Binary table.
Here is how to add Type 6 custom action in Wix:
<Binary Id="MyCA" SourceFile="MyCA.vbs"/>
VBScriptCall="Main"
First, we add MyCA.vbs to the Binary table.
We also add a custom action of Type 6 to the CustomAction table. BinaryKey attribute points to the <Binary> element with the custom action dll. VBScriptCall attribute specifies the script function to execute.
Custom Action Type 17
Calls a dynamic link library written in C/C++ which is installed with the application during current session.
The Source column in the CustomAction table contains the key to the record in the File table.
Because file is installed with the application, there are sequencing restrictions on custom action Type 17:
Here is how to add Type 17 custom action in Wix:
<Directory Id="TARGETDIR" Name="SourceDir">
<Component Id="Component1"
Guid="{A77C5B06-132D-4884-8E17-EA10A83C812D}">
<File Id="MyCA" Name="MyCA.dll" />
</Component>
</Directory>
FileKey="MyCA"
First, we add MyCA.dll to the File table.
We also add a custom action of Type 17 to the CustomAction table. FileKey attribute points to the <File> element with the custom action dll. DllEntry attribute specifies the name of the entry point function in the dll.
Custom Action Type 18
Calls an executable which is installed with the application during current session.
Because file is installed with the application, there are sequencing restrictions on custom action Type 18:
Here is how to add Type 18 custom action in Wix:
<File Id="MyCA" Name="MyCA.exe" />
First, we add MyCA.exe to the File table.
We also add a custom action of Type 18 to the CustomAction table. FileKey attribute points to the <File> element with the custom action dll. ExeCommand attribute specifies the command line string for the executable.
Custom Action Type 19
This custom action displays a specified error message, returns failure, and then terminates the installation.
The value of columns in the CustomAction table:
None of the return processing, execution scheduling, and in-script execution options apply.
Here is an example of custom action Type 19 in Wix:
<CustomAction Id='IsPrivileged' Error='You must be an admin to install this product' />
<Custom Action='IsPrivileged' Before='LaunchConditions'>
Not Privileged
</Custom>
Custom Action Type 21
Calls the JScript custom action which is installed with the application during current session.
Because file is installed with the application, there are sequencing restrictions on custom action Type 21:
Here is how to add Type 21 custom action in Wix:
<File Id="MyCA" Name="MyCA.js" />
First, we add MyCA.js to the File table.
We also add a custom action of Type 21 to the CustomAction table. FileKey attribute points to the <File> element with the custom action dll. JScriptCall attribute specifies the script function to execute.
Custom Action Type 22
Calls the VBScript custom action which is installed with the application during current session.
The Source column in the CustomAction table contains the key to the record in the File table. The Target column in the CustomAction table contains the optional script function to execute. All return processing, execution scheduling, and in-script execution options apply.
Because DLL is installed with the application, there are sequencing restrictions on custom action Type 22:
Here is how to add Type 22 custom action in Wix:
<File Id="MyCA" Name="MyCA.vbs" />
First, we add MyCA.vbs to the File table.
We also add a custom action of Type 22 to the CustomAction table. FileKey attribute points to the <File> element with the custom action dll. VBScriptCall attribute specifies the script function to execute.
Custom Action Type 34
Calls an executable which already exists on the target system and is not installed with the application during current session.
The Source column in the CustomAction table contains the key to the record in the Directory table. This record is used to resolve the full path to a working directory. This is not required to be the path to the directory containing the executable.
The Target column in the CustomAction table contains the full path and name of the executable file followed by optional arguments to the executable. The full path and name to the executable file is required. Quotation marks must be used around long file names or paths. The value is treated as formatted text and may contain references to properties, files, directories, or other formatted text attributes.
Here is how to add Type 34 custom action in Wix:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi">
<Product Id="{0BD4334D-F9FE-4B70-8070-917288A50B51}"
Name="Minimal Windows Installer Sample"
Language="1033"
Codepage="1252"
Version="1.0.0"
Manufacturer="Acme Corporation"
UpgradeCode="{770C5598-A538-4D44-8C2E-B2D94E15CC98}">
<Package Id="{E1782FB0-3D87-4B13-88DC-62E11FB72552}"
Description="Minimal Windows Installer Sample"
Comments="This installer database contains the logic and data required to install [ProductName]."
InstallerVersion="200"
Languages="1033"
SummaryCodepage="1252"
Platforms="Intel"
ReadOnly="no"
Compressed="yes"
AdminImage="no"
Keywords="Installer"
ShortNames ="no"
Manufacturer="Acme Corporation" />
<Media Id="1" Cabinet="CAB001.cab" EmbedCab="yes" />
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="Minimal" LongName="MinimalInstallation">
<File Id="ReadMe" DiskId="1" Name="Readme.txt" Source="Readme.txt" Vital="yes" KeyPath="yes" />
<CustomAction Id="ShowReadMe"
Directory="INSTALLDIR"
ExeCommand="[SystemFolder]notepad.exe [#ReadMe]"
Return="asyncNoWait" />
<Custom Action="ShowReadMe" After="InstallFinalize">Not Installed</Custom>
<Feature Id="Feature1"
Title="Feature1 title"
Description="Feature1 description"
Level="1"
ConfigurableDirectory="INSTALLDIR" >
<ComponentRef Id="Component1" />
</Feature>
</Product>
</Wix>
Here we are installing the ReadMe.txt file and using the custom action to show it's content in the notepad after installation is done.
Custom Action Type 35
Sets the target path and associated property of a record in the Directory table from a formatted text string.
The Source column in the CustomAction table contains the key to the record in the Directory table.
The Target column in the CustomAction table contains a formatted text and may contain references to properties, files, directories, or other formatted text attributes.
Only execution scheduling options apply.
Here is how to add Type 35 custom action in Wix:
<CustomAction Id="SetMergeModulesPath"
Directory="MERGEDIR"
Value="[ProgramFilesFolder]Common Files\Merge Modules" />
<Custom Action="SetMergeModulesPath" After="CostFinalize">Not Installed</Custom>
Important: Do not change the location of a target directory during maintenance installation.
Custom Action Type 37
Calls the JScript custom action stored internally in the CustomAction table.
The Source column in the CustomAction table contains the null value.
The Target column in the CustomAction table contains the script code for the custom action as a string of literal script text.
Here is how to add Type 37 custom action in Wix:
<CustomAction Id="CopyReadMe"
Script="jscript">
<![CDATA[
var fso = new ActiveXObject("Scripting.FileSystemObject");
var path = Session.Property("INSTALLDIR");
fso.CopyFile(path + "ReadMe.txt", path + "ReadMe2.txt");
]]>
</CustomAction>
<Custom Action="CopyReadMe" After="InstallFinalize">Not Installed</Custom>
Custom Action Type 38
Calls the VBScript custom action stored internally in the CustomAction table.
Here is how to add Type 38 custom action in Wix:
<Product Id="{94A35E02-D48F-48F1-AC1A-23F62489BBF4}"
UpgradeCode="{74069BA4-1D1C-4252-A074-B2EC0C746403}">
<Package Id="{????????-????-????-????-????????????}"
<RemoveFile Id="RemoveCopy" Name="ReadMe2.txt" On="uninstall" />
Script="vbscript">
Set fso = CreateObject("Scripting.FileSystemObject")
path = Session.Property("INSTALLDIR")
fso.CopyFile path & "ReadMe.txt", path & "ReadMe2.txt"
Custom Action Type 50
Calls an executable launched with a command line. Path and file name of the executable is stored in the property. Typical use for this custom action is to find the installation path for the executable using registry search first.
The Source column in the CustomAction table contains a key to the Property table for a property that contains the full path to the executable file..
The Target column in the CustomAction table contains the command line string for the executable identified in the Source column.
Here is how to add Type 50 custom action in Wix:
<!-- Find Zune's installation path -->
<Property Id="ZUNEFOLDER">
<RegistrySearch Id="ZuneReg"
Root="HKLM"
Key="SOFTWARE\Microsoft\Zune"
Name="Installation Directory"
Type="raw" />
</Property>
<!-- Set the property to the <path>\Zune.exe -->
<CustomAction Id="SetZunePath"
Property="ZunePath"
Value="[ZUNEFOLDER]Zune.exe" />
<!-- Custom action to start the executable -->
<CustomAction Id="StartZune"
ExeCommand=""
<Custom Action="SetZunePath" After="AppSearch">ZUNEFOLDER</Custom>
<Custom Action="StartZune" After="InstallFinalize">ZUNEFOLDER And Not Installed</Custom>
Custom Action Type 51
Sets the property's value from a formatted text string.
Replaceable parameters in the formatted text string are enclosed in the square brackets:
Here is how to add Type 51 custom action in Wix:
Custom Action Type 53
Calls the JScript custom action stored in the property.
The Source column in the CustomAction table contains a property name or a key to the Property table for a property containing the script text.
The Target column in the CustomAction table contains an optional script function name to be called.
Here is how to add Type 53 custom action in Wix:
<Product Id="{A28D84A5-1DFB-4F2F-8CB5-C2D7764C697F}"
UpgradeCode="{3E339FF5-0E8F-47F2-AB8B-3F800A46C69A}">
<Property Id="CopyProgram">
function main()
{
}
JScriptCall="main"
Property="CopyProgram">
Custom Action Type 54
Calls the VBScript custom action stored in the property.
Here is how to add Type 54 custom action in Wix:
<Product Id="{C02C2DF1-F74E-4C61-8D19-151D9E70D64B}"
UpgradeCode="{59F2FD01-3932-4F33-882B-6A6E1E2FE0CF}">
Guid="{EB3E1A26-CA6C-4143-BCFA-C9CD8BFD363C}">
Function Main()
Main = 1
End Function
Property="CopyProgram" />