Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a Wix checkbox value that defaults to checked to the registry

I have an installer authored with Wix. In the UI wizard, there's a checkbox that defaults to checked. I want to save the value of this checkbox to the registry for changes, repairs and upgrades using the (simpler version of the) "Remember Property" pattern described by Rob Mensching.

The checkbox implementation:

<Control Id="httpsCheckBox" Type="CheckBox" CheckBoxValue="true" X="30" Y="119" Width="139" Height="17" Text="Enable HTTPS services" Property="ENABLEHTTPS" />

The property definition:

    <Property Id="ENABLEHTTPS" value="true">
        <RegistrySearch Id="EnableHttpsRegistrySearch" Type="raw" Root="HKLM" Key="SOFTWARE\CompanyName\ProductName" Name="EnableHttps" />
    </Property>

And the property is written to the registry here:

    <Component Id="RegistryEntries">
        <RegistryKey Root="HKLM" Key="SOFTWARE\CompanyName\ProductName">
            <RegistryValue Name="EnableHttps" Value="[ENABLEHTTPS]" Type="string" />
        </RegistryKey>
    </Component>

The initial install works fine. The value in the registry is "true" if the checkbox is left checked or empty if it's unchecked.

The next time the installer is run, to install a new feature for example, the checkbox is always checked regardless of the value in the registry setting.

If I remove the default value from the property definition so that the checkbox is unchecked the first time the installer is run, everything works fine. The next time the installer is run the checkbox (and property) have the correct value from the registry.

It's like the RegistrySearch does not set the property if the registry value is empty.

Am I doing something wrong? Or is there a better way of doing this?

like image 898
Smiffy Avatar asked Dec 16 '11 09:12

Smiffy


1 Answers

Basically, the element will use the default value if the registry entry is not found or null, and that is what you are experiencing.

See the documentation here: http://wix.sourceforge.net/manual-wix3/wix_xsd_registrysearch.htm

Here is a solution to the problem: http://www.mail-archive.com/[email protected]/msg32524.html

    <Property Id="ENABLEHTTPS" >
         <RegistrySearch Id="EnableHttpsRegistrySearch" Type="raw" Root="HKLM" Key="SOFTWARE\CompanyName\ProductName" Name="EnableHttps" />
    </Property>

    <CustomAction Id="SetENABLEHTTPS" Property="ENABLEHTTPS" Value="1" Execute="firstSequence" />

    <Control Id="httpsCheckBox" Type="CheckBox" CheckBoxValue="1" X="30" Y="119" Width="139" Height="17" Text="Enable HTTPS services" Property="ENABLEHTTPS" />

    <InstallUISequence>
        <Custom Action="SetENABLEHTTPS" Before="AppSearch">NOT Installed AND NOT OLDERVERSIONDETECTED</Custom>
    </InstallUISequence>
    <InstallExecuteSequence>
        <Custom Action="SetENABLEHTTPS" Before="AppSearch">NOT Installed AND NOT OLDERVERSIONDETECTED</Custom>
    </InstallExecuteSequence> 
like image 68
Rami A. Avatar answered Sep 28 '22 22:09

Rami A.