Accessing or Setting Windows Installer Properties Through Deferred, Commit, and Rollback Custom Actions

InstallShield 2012 Spring

Project: This information applies to the following project types:

Basic MSI
InstallScript MSI

Deferred, commit, and rollback custom actions in Basic MSI and InstallScript MSI installations have access to only some of the built-in Windows Installer properties: CustomActionData, ProductCode, and UserSID. If you want a custom action to access any other properties during deferred, commit, or rollback execution, you can pass them as CustomActionData. You can do so by scheduling an immediate set-a-property type of custom action to set a property that matches the name of the custom action. The value of this property is then available in the CustomActionData property within the deferred, commit, or rollback custom action.

Using CustomActionData to Access a Property

The following example shows how to access the Windows Installer property SUPPORTDIR through a deferred InstallScript custom action.

To access SUPPORTDIR through a deferred InstallScript custom action:

1. In the Custom Actions and Sequences view, create a set-a-property custom action (type 51) called GetSUPPORTDIR. Configure the Property Name, Property Value, and Install Exec Sequence settings for the custom action as follows, and leave all of the other settings blank.
Property Name: DisplaySupportDir
Property Value: [SUPPORTDIR]
Install Exec Sequence: After InstallInitialize
2. In the InstallScript view, create a new function called DisplaySupportDir.
3. Add the following code to display a message box containing the value of SUPPORTDIR:

function DisplaySupportDir(hMSI)

   STRING supportDirPath;

   NUMBER supportDirPathBuffer;

begin

   supportDirPathBuffer = MAX_PATH;

   if(MsiGetProperty(hMSI, "CustomActionData", supportDirPath, supportDirPathBuffer) == ERROR_SUCCESS) then

     SprintfBox(INFORMATION,"Deferred Execution","The value of SUPPORTDIR is %s",supportDirPath);

     SprintfBox(INFORMATION,"Deferred Execution","The value of InstallScript's SUPPORTDIR is %s",SUPPORTDIR);

   endif;

end;

4. In the Custom Actions and Sequences view, create an InstallScript custom action called DisplaySupportDir. Configure the Function Name, In-Script Execution, and Install Exec Sequence settings for the custom action as follows, and leave all of the other settings blank.
Function Name: DisplaySupportDir
In-Script Execution: Deferred Execution in System Context
Install Exec Sequence: After GetSUPPORTDIR

Important: The property name that you enter in step 1 must match the name of the custom action that you create in step 4.

Using CustomActionData to Access More Than One Property

If you want a deferred, commit, or rollback custom action to access more than one Windows Installer property, you can "pack" the properties in CustomActionData and then have your deferred, commit, or rollback custom action "unpack" them after retrieving the value of CustomActionData.

For example, if you want to retrieve the values of [INSTALLDIR], [SUPPORTDIR], and [SetupType], you would set the Property Value setting of your type 51 custom action to this:

[INSTALLDIR];[SUPPORTDIR];[SetupType]

where each property is separated by a semicolon.

You can use code such as the following VBScript to "unpack" the values from the CustomActionData property:

Dim PropArray

PropArray = Split(Session.Property("CustomActionData"), ";")

INSTALLDIR = PropArray(0)

SUPPORTDIR = PropArray(1)

SetupType = PropArray(2)

'Now do something with these variables...