How to set an installer property using custom actions

Windows Installer properties are global variables that Windows Installer uses during an installation. There are two main types of Windows Installer properties:

  • Private Properties (contain lower-case letters in their name, example: My_Prop)
  • Public Properties (contain only upper-case letters in their name, example: MY_PROP)

The difference between Public and Private properties consists in the way their values are being passed on. Only the value of a Public Property is passed on from the Wizard Dialogs Stage (in which the dialogs are showed) to the Install Execution Stage (in which the system is modified).

In order to get or set an installer property, you can use the following methods:

1. Get and set a property in a DTF C# custom action:

// getting a property
MyVariable = session["MyProperty"];

// setting a property
session["MyProperty"] = "MyValue";
      

To call a function from a dll, you can use the predefined Call function from attached native DLL custom action. For details, please check the Options to integrate and debug custom actions article with related information for hints and guidance.

2. Get and set a property in a C++ custom action:

// getting a property
MsiGetProperty(aHandle, L"MyProperty", MyVariable, &propertySize);

// setting a property
MsiSetProperty(aHandle, L"MyProperty", MyVariable);
      

For details, please check the MsiGetProperty function and MsiSetProperty function.

3. Get and set a property in Windows PowerShell Script custom action:

# getting a property
$propValue = AI_GetMsiProperty MY_MSI_PROP

# setting a property
AI_SetMsiProperty MY_MSI_PROP "MyValue"
      

NoteThe above example only works for immediate custom actions, for more information about getting properties into deferred custom actions please follow Run Windows PowerShell Script acrticle.

4. Get and set a property in a Visual Basic and Java scripts custom action:

// getting a property
MyVariable = Session.Property("MyProperty")

// setting a property
Session.Property("MyProperty") = "MyValue"
      

To execute a VBScript or a JavaScript you can use the predefined Execute inline script code or Launch attached file custom actions.

We recommend you to use a DLL custom action for example, you can create your custom action as a custom action written in C# or a custom action written in C++, instead of VBScript or JavaScript.