How to use an MSI installer property in condition message in WiX installer?

0

I want to use an MSI installer property in a condition message in a WiX installer. This MSI property is set by a C++ custom action. I can set and get the same MSI property and value before calling the condition message, but it is failing when I use it in condition message.

My condition message is looks like

<CustomAction Id="CustomAction1" BinaryKey="CustomDLL"
              DllEntry="CustomAction1" Execute="immediate" Return="check" />

<InstallUISequence>
 <Custom Action="CustomAction1" Before="LaunchConditions">Not Installed</Custom>
</InstallUISequence>

<InstallExecuteSequence >
 <Custom Action="CustomAction1" Before="LaunchConditions">Not Installed</Custom>
</InstallExecuteSequence>

<Condition Message="message comes here.">
 <![CDATA[(MyProperty= "NO")]]>
</Condition>

Here this MyProperty is a string and returns either YES or NO, and it is set by C++ CA and this condition is failing in both cases. But I want to show this message only when the MyProperty is set to "NO".

So how do I use my custom MSI property in a condition message that was set by a custom action?

Anna

Posted 2014-01-20T13:04:19.247

Reputation: 31

Answers

0

I would try to UPPERCASE the property MyProperty to make it a PUBLIC property, and then I would also declare it in your WiX source via a Property Element and set the Secure attribute to Yes and see if that helps. The WiX markup:

<Property Id='MYPROPERTY' Secure='yes' />

I would also retrieve the property after you set it in your C++ custom action to determine if it has been set correctly (it could be blank). Using VBScript you can retrieve the property very easily. Here is a sample (VBScript helps avoid any compilation and you can embed the source in the custom action - great for testing purposes - and use it only for testing purposes):

MsgBox Session.Property("MYPROPERTY")

As a WiX element, something like this (can't test right now - give it a try - remember to insert in the InstallUISequence or InstallExecuteSequence):

<CustomAction Id="Test" Script="vbscript">
   <![CDATA[MsgBox Session.Property("MYPROPERTY")]]>
</CustomAction>

I believe this should help you sort out what the problem really is.

You can use the WiX Property element to test the condition by hard coding a value outright (in case the C++ code set property call is the problem). The following should make your launch condition evaluate to false (triggering the message you specified to show):

<Property Id='MYPROPERTY' Secure='yes' Value="YES" />

Stein Åsmul

Posted 2014-01-20T13:04:19.247

Reputation: 969

-1

Coding questions are better placed on https://stackoverflow.com/

The answer to this question is a lot more complicated than it should be. Please check if this post gets you going in the right direction, and I will check back to see if your problem was solved: https://stackoverflow.com/questions/3252448/visual-studio-deployment-project-customactiondata

In addition to what that question mentions, make sure your property is listed in the delimited list of "secure properties" in the SecureCustomProperties Property.

All this complexity stems from Windows Installer's complex "elevated priviledges" concept that allows non-administrator users to install with elevated rights at times. For this to work no properties can be accessed directly in the transaction that runs with elevated rights, and you must specifically write their value into the execution script and retrieve them in a rather exotic way as you will see in the linked articles. It involves reading back a property called CustomActionData.

Finally, and importantly; post on stackoverflow.com also. WiX may have a more advanced way to deal with this complexity at this stage that I am not aware of. Some sort of automagic.

Stein Åsmul

Posted 2014-01-20T13:04:19.247

Reputation: 969

This answer relates to a more complicated scenario where you need to retrieve the property in question in deferred mode - in which case it has to be written into the execution script, and retrieved via the special CustomActionData property. Quite clunky, and probably not what the OP asked about in this case. See my new answer instead. – Stein Åsmul – 2018-05-24T23:09:31.113