0
votes

To create an MSI, I use the Gradle plugin SetupBuilder.

After the installation, I need to execute a binary from the installation directory. But I'm unable to access the INSTALLDIR property:

msi {
  postinst = '''
MsgBox ("INSTALLDIR: " & Session.Property("INSTALLDIR"))
'''
}

But:

INSTALLDIR is empty

I found that SetupBuilder creates the following custom actions in the .wxs file:

    <CustomAction Execute="deferred" Id="Postinst_Script0" Impersonate="no" Script="vbscript">
MsgBox ("INSTALLDIR: " &amp; Session.Property("INSTALLDIR"))
</CustomAction>

<CustomAction Id="SetPropertiesPostinst_Script0" Property="Postinst_Script0" Value="INSTALLDIR='[INSTALLDIR]';ProductCode='[ProductCode]';INSTANCE_ID='[INSTANCE_ID]'"/>

They're then called like this:

<InstallExecuteSequence>
  <Custom Action="Postinst_Script0" Before="InstallFinalize">NOT Installed OR REINSTALL OR UPGRADINGPRODUCTCODE</Custom>
  <Custom Action="SetPropertiesPostinst_Script0" Before="Postinst_Script0"/>
</InstallExecuteSequence>

According to the WiX documentation on CustomAction Element, the combination of Property and Value should result in a Custom Action Type 51 and this is pretty much where I get lost. Too many unknowns to understand, just for accessing a simple property.

Can someone please help me understand; how do I access the property?

2
The operations that you apply, do they require administrator rights? If not you can just as well use application launch to apply settings. Easy fix. Much easier to debug and maintain.Stein Åsmul

2 Answers

1
votes

You can try:

MsgBox ("CustomActionData: " & Session.Property("CustomActionData"))

If this work you can try:

Dim properties
loadCustomActionData properties
MsgBox ("INSTALLDIR: " & properties("INSTALLDIR"))

' =====================
' Decode the CustomActionData
' =====================
Sub loadCustomActionData( ByRef properties )
    Dim data, regexp, matches, token
    data = Session.Property("CustomActionData")

    Set regexp = new RegExp
    regexp.Global = true
    regexp.Pattern = "((.*?)='(.*?)'(;|$))"

    Set properties = CreateObject( "Scripting.Dictionary" )
    Set matches = regexp.Execute( data )
    For Each token In matches
        properties.Add token.Submatches(1), token.Submatches(2)
    Next
End Sub
1
votes

There could be several possible answers to your question:

  1. The MSI package does not contain INSTALLDIR property since it's non-standard and should be created explicitly.
  2. You're trying to access it in a deferred custom action. This will not work because only a limited number of properties are available in deferred mode. To get access to any other properties you should use CustomActionData property. You can read more about it here and here.