Reputation: 149
I want to validate the value of a command line property in WiX given by the user during installation. If the value of the property is not one among the specific set, it should take a default value and create a registry entry.
For example, property USERLEVEL should have value 1-4. If user specifies any other value it should default to 1 and write it to the registry. The installer does not have a UI component and we want to do this using some conditional statement.
Upvotes: 2
Views: 1465
Reputation: 1995
You can use the SetProperty element to change the USERLEVEL property value. You can use the (USERLEVEL<1 OR USERLEVEL>4) Condition to check the value, but it won’t work if end user pass any non-integer value like ‘A’.
<Property Id="USERLEVEL" Secure="yes" />
<SetProperty Id="USERLEVEL" Value="1" After="AppSearch">
USERLEVEL<>1 AND USERLEVEL<>2 AND USERLEVEL<>3 AND USERLEVEL<>4
</SetProperty>
You can use the below code to write the property into registry.
<Component Id="CMP_UserLevel" Guid="{FD70BBE3-F7F1-460E-AA7C-56750F66536D}">
<RegistryKey Root="HKLM" Key="Software\Sample, Inc.\Test Installer">
<RegistryValue Name="USERLEVEL" Value="[USERLEVEL]" Type="integer" />
</RegistryKey>
</Component>
Upvotes: 0
Reputation: 35976
That can be done easiest with a "Launch Condition". As a child of Product
element add a Condition
element with a message. For example:
<Product ...>
...
<Condition Message='The USERLEVEL property has an invalid value of: [USERLEVEL]. Please ensure the value falls in the range of 1 to 4.'>
USERLEVEL>0 AND USERLEVEL<5
</Condition>
I used the >
and <
rather than wrapping the condition in CDATA
but you can do it however you like. The end result is that you want the condition to say something like USERLEVEL > 0 and USERLEVEL < 5
(or if you prefer: USERLEVEL >=1 AND USERLEVEL <= 4
).
Upvotes: 2