How can I have a WiX Property default to null? - wix

I am working on a set of WiX installers that are going to share a common form. Every application needs the values set, but they are going to be different for each application.
I am trying to allow for the properties (which are linked to controls) to have a default value (or not) and to allow for the property values to be set via command line.
in my "SharedDialog.wxs" I have:
<Fragment>
<PropertyRef Id="PROP1"/>
<PropertyRef Id="PROP2"/>
<UI>
<Dialog Id="SharedDialog" Width="370" Height="270" Title="[ProductName]">
<Control Type="Edit" Id="1" Property="PROP1" Wid... Indirect="no" />
<Control Type="CheckBox" Id="2" Property="PROP2" Wid...
CheckBoxValue="1" Indirect="no"/>
</Dialog>
</Fragment>
In a file for the application specific project:
<Fragment>
<Property Id="PROP1" Value="Test"/>
<Property Id="PROP2" Value="1"/>
</Fragment>
This all works for what I am trying to do, but the problem is that when I want to clear the values as so: (so they don't have a default)
<Fragment>
<Property Id="PROP1"/>
<Property Id="PROP2"/>
</Fragment>
I get this error:
Unresolved reference to symbol 'Property:PROP1' in section 'Fragment:'.
Unresolved reference to symbol 'Property:PROP2' in section 'Fragment:'.
WiX also will not let you set value to "". The problem is that as far I can tell the checkbox will always be checked if the property has a value. How can I set the property "PROP2" to "null"?

You can undefine an existing property by setting it equal to an empty string wrapped in braces like this: PROPERTY = {} in a set property custom action. This means the property doesn't exist, it is not an empty string. See the explanation here.
For properties to be available from the command line they must be PUBLIC - they are the properties that are all UPPERCASE.
Setting PUBLIC PROPERTIES secure means they can be passed from the client to the server installation process which is required for properties that are used in deferred mode custom actions. Technically this adds them to the list of SecureCustomProperties.
You can give PUBLIC PROPERTIES a default value in the Property table, and then set other values from the command line. The command line overrides the defaults:
msiexec.exe /I "C:\Test.msi" /QN /L*V "C:\log.log" TEST="MyValue" TEST2="MyValue"
See more info:
How to set a check box to "unchecked" from the msiexec command line?

Nevermind, I found the solution:
<Fragment>
<Property Id="PROP1" Secure="yes"/>
<Property Id="PROP2" Secure="yes"/>
</Fragment>

Related

WIX: Setting a registry value from a dialog checkbox

Using Wix for the first time in 10+ years, and first time with forms/dialog entry.
Have a property defined more or less like this:
<Property Id="THE_FLAG">
<RegistrySearch Id="SearchTheFlag" Root="HKLM" Key="SOFTWARE\$(var.Manufacturer)\$(var.SimpleProductName)" Name="the_flag" Win64="$(var.Win64)" Type="raw" />
</Property>
Have a control in a form to set it:
<Control Id="TheFlagCheckBox" Type="CheckBox" X="45" Y="80" Width="220" Height="17" Property="THE_FLAG" CheckBoxValue="1" Text="Flag for something" />
At the end I want to write it:
<RegistryKey Root='HKLM' Key='SOFTWARE\$(var.Manufacturer)\$(var.SimpleProductName)' ForceCreateOnInstall='yes' >
<RegistryValue Name='the_flag' Type ='integer' Value='[THE_FLAG]' />
</RegistryKey>
If I select the checkbox, it sets the registry value. However, if I don't check the checkbox, then I get a warning when running the installer about not being able to acces the registry value. I think it is because the "value" of "THE_FLAG" is null or the empty string. I want to avoid the nasty warning to the user. I took over some code, and the previous owner used all strings for obviously DWORD values...maybe to get around the warning.
Can I set some conditionals or set the value of THE_FLAG to "0" if it is "" or null?
Add the following to your authoring:
<SetProperty Id="THE_FLAG" Value="0" Before="InstallInitialize" Sequence="execute">NOT THE_FLAG</SetProperty>
This will set the value of THE_FLAG to "0" if it's blank (in MSI, null and empty string are both blank) before the registry writes are done. A reasonable alternate value for Before is "WriteRegistryValues".

Set the Property value to an ini file WIX

I was setting a property value inside a Dialog using Edit Control. But when i used the same property for writing inside an ini value it is not writing the updated value and writing only old value. My WIX source code is given below(writing only important codes as my wix code is too large)
<Property Id="testNumber" Value="1122" />
<CustomAction Id="SettestNumber" Property="ModifiedtestNumber" Value="[testNumber]" />
<ComponentGroup Id="INIFileGroup">
<Component Id="IniFile" Guid="{0ded271b-9268-49e7-8c13-60c7538acc25}" KeyPath="yes" Directory="DirCfg" >
<IniFile Id="IniPath" Action="addLine" Directory="Dirtest" Key="testkey" Name="test.ini" Section="test" Value="[ModifiedtestNumber]" />
</Component>
</ComponentGroup>
<InstallUISequence>
<Custom Action="SettestNumber" Sequence="1299"/>
</InstallUISequence>
<Dialog Id="testNumberUI" X="50" Y="50" Width="375" Height="270" Title="[ProductName]" CustomPalette="yes">
<Control Type="Edit" Id="test_Number" Width="50" Height="15" X="258" Y="53" Property="testNumber" Text="{50}" TabSkip="yes"/>
</Dialog>
I am giving the value 1212 in the Control edit box and installing but inside the test.ini file it is not getting updated and value is 1122. Could someone please provide a way for me to update the Modifedtestnumber to the ini file
Note:
When i put the Custom action inside < InstallExecuteSequence/> the value inside the ini file was null
Your property need to be public (all caps TESTNUMBER) and marked with Secure attribute so that it's listed in the SecureCustomPublicProperties property. Also be aware that properties are not persisted. You need to use something like the WiX remember property pattern for the value to be loaded from the INI file during subsequent transactions such as repairs and upgrades.

'Remember Property' pattern and the property used in RadioButtonGroup

I'm trying to save the property value in registry during setup and read it next time installation is run.
I follow 'Remember property' pattern as described here
It basically works as expected, but I cannot get one scenario working:
I run setup (property gets stored in the registry)
I run setup again without entering property value on command line
I expect value of the property to be read from registry, but it is assigned default value.
I think, I know where is the problem: I have "Value" assigned to the property, while the example I've mentioned above, declares "remembered" property without "Value". In my package, I have to define the value as I use the property in UI element with RadioButtonGroup. If I don't declare Value field of the property, I get compilation error:
error LGHT0204 : ICE34: Property LOCATION (of RadioButtonGroup control LocationSelection.InstallationLocation) is not defined in the Property Table.
Can anybody give me a hint how to manage it?
Here is solution draft:
Custom actions to fill properties
<CustomAction Id='SaveCmdLineValueLocation' Property='CMDLINE_LOCATION'
Value='[LOCATION]' Execute='firstSequence' />
<CustomAction Id='SetFromCmdLineValueLocation' Property="EFFECTIVE_LOCATION"
Value='[CMDLINE_LOCATION]' Execute='firstSequence' />
<CustomAction Id='SetFromRegValueLocation' Property="EFFECTIVE_LOCATION"
Value='[REG_LOCATION]' Execute='firstSequence' />
Execute sequence that assignes EFFECTIVE_LOCATION either from registry or msiexec command line:
<InstallExecuteSequence>
<Custom Action='SaveCmdLineValueLocation' Before='AppSearch'>
LOCATION
</Custom>
<Custom Action='SetFromCmdLineValueLocation' After='AppSearch'>
CMDLINE_LOCATION
</Custom>
<Custom Action='SetFromRegValueLocation' After='AppSearch'>
REG_LOCATION AND (NOT CMDLINE_LOCATION)
</Custom>
</InstallExecuteSequence>
Properties declaration:
<!-- Property used on command-line. -->
<Property Id="LOCATION" Secure="yes">
</Property>
<!-- Property used finally with ReadioButtonGroup. It must have Value assigned (required when used with RadioButtonGroup -->
<Property Id="EFFECTIVE_LOCATION" Value="OFFICE" Secure="yes">
</Property>
<!-- Read previous value from registy (from recent installation) -->
<Property Id="REG_LOCATION" Secure="yes">
<RegistrySearch Id="loc" Root="HKLM" Key="SOFTWARE\Company\Product" Type="raw" Name="LOCATION" Win64='yes'>
</RegistrySearch>
</Property>

Storing Checkbox value in a Property Wix 3.7

Currently I am working on a simple project in which i have to modify an xml file using user input in WIX 3.7. Everything goes fine except in case of checkbox.
I have created a Property and then using that property in a checkbox type of control. I need that if the checkbox is checked then Node value will be modified to 1 and if not then 0.
Below is the code i have used.
<Property Id="ISPATH" Secure="yes"></Property>
<Control Id="checkBox1" Type="CheckBox" Height="18" Width="67" X="104" Y="108" Text="Is-Path" Property="ISPATH" CheckBoxValue="1" >
</Control>
<util:XmlFile Id="ModifyPath" Action="setValue" Permanent="yes" ElementPath="/DataBaseSettings/IsPath"
File="[#Settings]" Value="[ISPATH]" SelectionLanguage="XSLPattern" Sequence="1" />
No Change is seen in ISPATH property.
Any Suggestions????

How to inspect a CustomAction's property (Wix)?

I am trying to put together a small 'prerequisites' dialog in Wix to give confidence to the users that they have all of the required things needed to run my software:
For example, I have a need for Managed DirectX, so I look for some DLLs:
<Property Id="MANAGED_DIRECTX">
<DirectorySearch Path="$(env.SystemRoot)\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" Depth="0" Id="MDXDir">
<FileSearch Name="Microsoft.DirectX.dll"/>
</DirectorySearch>
</Property>
<Property Id="MANAGED_DIRECTX_DIRECTINPUT">
<DirectorySearch Path="$(env.SystemRoot)\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" Depth="0" Id="MDXInputDir">
<FileSearch Name="Microsoft.DirectX.DirectInput.dll"/>
</DirectorySearch>
</Property>
I also have a CustomAction to combine my condition logic:
<CustomAction Id="SetManagedDirectXInstalled"
Property="MANAGED_DIRECTX_INSTALLED"
Value="NOT([MANAGED_DIRECTX] = '') AND NOT ([MANAGED_DIRECTX_DIRECTINPUT] = ''")/>
This CustomAction is sequenced:
<InstallExecuteSequence>
<Custom Action="SetManagedDirectXInstalled" After="AppSearch" />
<RemoveExistingProducts After="InstallInitialize" />
</InstallExecuteSequence>
What I should now be able to do is use "MANAGED DIRECTX INSTALLED" to do something, e.g.
<Control Id="NoManagedDirectX" Type="Text" X="20" Y="50" Width="300" Height="60" Transparent="yes" NoPrefix="yes" Hidden="yes">
<Text>Microsoft Managed DirectX (MDX) for DirectX 9.0 is NOT installed</Text>
<Condition Action="show">NOT MANAGED_DIRECTX_INSTALLED</Condition>
</Control>
<Control Id="ManagedDirectX" Type="Text" X="20" Y="50" Width="300" Height="60" Transparent="yes" NoPrefix="yes" Hidden="yes">
<Text>Microsoft Managed DirectX (MDX) for DirectX 9.0 is correctly installed</Text>
<Condition Action="show">MANAGED_DIRECTX_INSTALLED</Condition>
</Control>
It doesn't matter what I do, the condition is always false (e.g. not installed) even when I know the files are there. Using the msiexec command with /l*vx does not show the MANAGED DIRECTX INSTALLED property anywhere.
When a <Condition> is used with the following, it successfully prevents installation (although I no longer want to block installs in this case, just advise).
<Condition Message="You must have Microsoft Managed DirectX (MDX) for DirectX 9.0 installed">
MANAGED_DIRECTX AND MANAGED_DIRECTX_DIRECTINPUT
</Condition>
How can I trace/debug this (or what have I done wrong?)
EDIT - I'm now certain that my CustomAction is not even being called, setting it to the following is not showing expected results either!
<CustomAction Id='SetManagedDirectXInstalled'
Property='MANAGED_DIRECTX_INSTALLED'
Value='Something hard-coded'/>
or
<CustomAction Id='SetManagedDirectXInstalled'
Error='Some error should show!'/>
I think I may have found the answer, but I can't try it until I'm next at my development PC.
It appears I have to compare the values to TRUE/FALSE (or empty string) not just expecting it to work as boolean (Source)
In these expressions, you can use
property names (remember that they are
case sensitive). Non-existent property
names will be treated as empty
strings. The logical value of a
property reflects whether it has been
set—meaning that you cannot check for
a logical value by simply using the
property:
PROPERTY
This will evaluate to true if the property has been set and has any
value, even if this value is false.
NOT PROPERTY
This will evaluate to true if the property has not been set at all.
PROPERTY = TRUE
PROPERTY = FALSE
This is the proper way to check the value of a logical property.
To debug, use a verbose log file. It will show you the states of your Properties as they change. You should then be able to evaluate the Condition with that knowledge
I answered this same question not too long ago here. A Condition that uses the Property name is a test for existence. An existence test for a Property evaluates to true if the Property has any value at all. If you want to check the value of a Property you need to do so explicitly.