Sajo Jacob

I am back blogging, almost 2 years after I decided to abandon my good ol C/C++ blog, so here goes my ramblings...
in

CustomActionData in WiX with Deferred Custom Actions

Here is a major gotcha that you will encounter when you try to configure your product with 
deferred actions using configurable properties during the installation.
 
Deferred actions do NOT have access to the MSI session objects which means that if you try 
to get the value of a property set by the installer like:

 

Value = Session.Property( "Property1" )

 

in a VBScript custom action which is deferred, It will return null. Yes, you just lost the

original value of Property1 during deferred custom actions.

Here is where CustomActionData comes to the rescue, let’s see how this works
 
Your deferred Custom Action:
 

<CustomAction Id=" MYCustomDeferredAction " Return="check" Execute="deferred"

BinaryKey="MYVBSCRIPT" VBScriptCall=" MyVBScriptMethod" />
 
Now let’s create a new custom action which will run as immediate: 
 
<!--Note I am passing 2 values delimted by a ‘,’ in this example-->
<CustomAction Id=" SetCustomActionDataValue " Return="check" Property="MYCustomDeferredAction" 
Value="&quot;[Value1]&quot;,&quot;[Value2]&quot;" />

And in the InstallExecuteSequence place the CustomActionData custom action before the
 actual custom action is executed:

<Custom Action="SetCustomActionDataValue" After="CAction1">
    <![CDATA[ ( Place any conditions here…)]]>
</Custom>

<Custom Action=" MYCustomDeferredAction " After=" SetCustomActionDataValue ">
    <![CDATA[ ( Place any conditions here…)]]>
</Custom>

 
And now in the VBScript just do a split to parse out the 2 values from the CustomActionData
and you are done!

' VBScript source code

Delim = ","

strArgs = Session.Property("CustomActionData")

Args = Split( strArgs, Delim )

Value1 = Args(0)

Value2= Args(1)

Comments

David Hacker said:

I have definitely ran into this issue in the past so hopefully this helps someone out.  Another thing regarding MSI properties that comes to mind is setting the SecureCustomProperties property when running installs on Vista.

msdn2.microsoft.com/.../aa371571(VS.85).aspx

As the above link states,  SecureCustomProperties allows the passing of public properties to " to the server side when doing a managed installation with elevated privileges.".  

# March 2, 2008 7:49 AM

Trixi said:

Thank you.

# June 19, 2008 9:20 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)