Wahaj Ali
Wahaj Ali

Reputation: 4113

WIX condition only on Install not working

I have the following within the Product Tag:

<Property Id="LICENSEKEY" Admin="yes" Hidden="no">
  <RegistrySearch Id="RememberLicenseKey" Root="HKLM" Key="SOFTWARE\MyApp\key1\Settings" Name="LICENSEKEY" Type="raw"></RegistrySearch>
</Property>

<Condition Message="License key is required to proceed">LICENSEKEY AND NOT Installed</Condition>

What I want to do is pass the License key as a command line argument to msiexec, and then set it in the registry. If the key is not passed I want to cancel the installation. Therefore, this check only needs to be run at install time. However, the condition that I have added causes a popup both at install and uninstall time. Can't seem to figure out what I am doing wrong.

EDIT: I tested with the following condition and it seems to show the message both on install and uninstall:

<Condition Message="License key is required to proceed">NOT Installed</Condition>

Upvotes: 1

Views: 3324

Answers (2)

JeremyE
JeremyE

Reputation: 415

The Message for a Condition element will be displayed when the condition evaluates to false, meaning the condition was not met.

This is noted in the Message attribute description in the WiX Condition documentation:

Set the value to the text to display when the condition fails and the installation must be terminated.

To resolve this issue, the logical operators in the Condition just need to be changed to LICENSEKEY OR Installed

This is a late answer, but, hopefully, this will help any future visitors that find this question.

Upvotes: 3

PhilDW
PhilDW

Reputation: 20790

You may need to clarify your requirement. That WiX source does a search for the key, so does it need to be passed on command line or you'll cancel the install (as your post says), or can it be used if it's found in the registry by that registry search? Currently it appears that your registry search is overwriting anything you pass on the command line, including setting it to null, so check that with a verbose log.

Also, all the launch condition examples I've seen or used have a CDATA around the text of the actual condition - that may be part of the problem.

I'll assume you allow the key on the command line or in the registry. So your registry search should be for another property name, let's call it REGKEY, so it doesn't set your passed LICENSEKEY to null. Then you have a set property (type 51) custom action immediately after the search that sets LICENSEKEY to REGKEY with a condition of -Not LICENSEKEY- so it will set LICENSEKEY to REGKEY only if LICENSEKEY was not passed on the command line. So if you pass it on the command line it will be used, otherwise the registry one will be used. At that point, a condition of LICENSEKEY should work ok as a launch condition. Internally, the AppSearch that finds the registry item is typically immediately followed by the launch condition check in a WiX MSI, so you need to set LICENSEKEY before the launch condition check.

Upvotes: 0

Related Questions