A Step-by-Step Guide to Transferring CustomActionData During WiX CustomAction Execution

A Step-by-Step Guide to Transferring CustomActionData During WiX CustomAction Execution

Donald Lv12

A Step-by-Step Guide to Transferring CustomActionData During WiX CustomAction Execution

Versus

Inno SetupInno SetupWiX ToolsetWiX ToolsetInstallShieldInstallShieldMSIX Packaging ToolMSIX Packaging Tool

icon subscribe mail

Check your inbox and confirm the
subscription

Exclusive NewsletterExclusive Newsletter

Exclusive NewsletterExclusive Newsletter

Get the latest WiX insights direct to your inbox. Subscribe now!

Disclaimer: This post includes affiliate links

If you click on a link and make a purchase, I may receive a commission at no extra cost to you.

How to pass CustomActionData to a CustomAction using WiX

Written by Horatiu Vladasel · September 9th, 2022

Do you want to transfer CustomActionData to a CustomAction in WiX? We’ll show you how in this article.

When adding CustomActions using WiX, there are two elements that you need to use:

  • the CustomAction element;
  • the Sequence element.

The CustomAction element specifies the custom action that will be added to the MSI CustomAction table.

On the other hand, the Sequence element is used to schedule the CustomAction within the corresponding table (AdminExecuteSequence, AdminUISequence, AdvertiseExecuteSequence, InstallExecuteSequence) and set any condition, if needed.

Each condition is evaluated separately, and the corresponding CustomAction is run only if the condition is set as True. Otherwise, the CustomAction gets skipped. If the condition syntax is invalid, then the sequence ends and returns iesBadActionData.

NoteGet more details about WiX CustomActions from our How To Add Custom Actions in WiX Toolset article.

What is the challenge when you want to pass a property to a Deferred CustomAction?

A Deferred CustomAction doesn’t have any information about the original session handle and property data (Session.Property([PROPERTY])). This is because the script generated for it is executed outside of the installation process. Instead, you will need to use CustomActionData (Session.Property(“CustomActionData”)) .

How to use CustomActions with WiX?

Let’s suppose we need to add a script that takes the value of the SERVERPATH property as an input (passed to the installer via command line) and writes it into the registry. The CustomAction script should look like the one below:

First, we must define our CustomAction elements:

Copy

Let’s understand what SetServerPathProperty and SetServerPath CustomAction are:

  • The SetServerPath CustomAction is the Deferred CustomAction and it references the VBScript defined above, which is stored in the Binary table.
  • The SetServerPathProperty is the SetProperty CustomAction which is used to set the property of interest (SERVERPATH) property to a property with the same name as the Deferred CustomAction (SetServerPath).

We also need to define the Binary element because the VBScript referenced by the SetServerPath CustomAction is stored in the Binary table.

Copy

Once the CustomAction and Binary elements are defined, we can set the corresponding InstallExecuteSequence elements – one for each of the two CustomActions.

NOT Installed NOT Installed

Copy

NoteWhen scheduling the two CustomAction in the InstallExecuteSequence table, the SetProperty CustomAction (‘SetServerPathProperty) should be scheduled before the Deferred CustomAction (SetServerPath).

SetProperty CustomAction (‘SetServerPathProperty) is used to set the property of interest to a property with the same name as the Deferred CustomAction.

The complete listing for the WiX source file (.wxs) should look like the one below:

NOT Installed NOT Installed

Copy

Now, all we need to do is to:

  • Pre-process and compile the WiX source file into a WiX object file.
  • Process the WiX object file compiled previously and build the Windows Installer (MSI package).
https://techidaily.com

How to configure CustomActions with Advanced Installer?

If you use Advanced Installer to build and create your MSI, there is no need for an extra CustomAction to set the property of interest with the same name as the Deferred CustomAction.

All you need to do is specify the value of the CustomActionData property within the “ActionData” and Advanced Installer does the rest for you.

Configure CustomActions

NoteHave a look at our How to Use CustomActionData to Access Windows Installer Properties in Deferred CustomActions article to find out more about:- Why do you need CustomActionData- When can Deferred CustomActions go wrong- How you can pass CustomActionData to a CustomAction using Advanced Installer

https://techidaily.com

Conclusion

WiX does not have a GUI and it builds the Windows Installer packages based solely on the information defined within the WiX source file (wxs). This makes it difficult to use, especially for people who have little or no experience.

On the other hand, Advanced Installer comes with a dedicated GUI for adding a CustomAction and passing the CustomActionData property to it which makes the job a lot easier and very intuitive.

Try out Advanced Installer’s dedicated GUI for CustomAction through our 30-day full feature trial .

Advanced Installer #1 alternative to the WiX Toolset

We decided to focus on our main goal to save precious time of our developers.

HANS-LEO TEULINGS
PHD – CEO, NEUROSCRIPT, LLC

You might find useful:

https://techidaily.com

Get the most from packaging with Advanced Installer

Try the 30-day fully-featured edition absolutely free!

Download Free Trial

No credit card required

Also read:

  • Title: A Step-by-Step Guide to Transferring CustomActionData During WiX CustomAction Execution
  • Author: Donald
  • Created at : 2024-10-01 19:11:47
  • Updated at : 2024-10-03 20:02:35
  • Link: https://some-tips.techidaily.com/a-step-by-step-guide-to-transferring-customactiondata-during-wix-customaction-execution/
  • License: This work is licensed under CC BY-NC-SA 4.0.