Gilad Dahan
Gilad Dahan

Reputation: 558

WiX installer - Read from registry to checkbox value

I am fairly new to WiX and I got an issue where I cannot read a value from the registry to a Checkbox. I can read and populate to a ComboBox properly from the registry but for some reason the checkbox is not working.

Here is a part of my CustomUI.wxs

 <Property  Id="HEAPSIZEVALUE" Value="-Xms1024m" Secure="yes">
      <RegistrySearch Id="RegHeapSizeValue" Type="raw" Root="HKCU"
                             Key="Software\Altair Semiconductor\!(loc.ProductName)" Name="Heap_Size" />
    </Property>
    <Property  Id="POWERMODE" Value="1" Secure="yes">
      <RegistrySearch Id="RegPowerModeValue" Type="raw" Root="HKCU"
                             Key="Software\Altair Semiconductor\!(loc.ProductName)" Name="Power" />
    </Property>
    <SetProperty Id="POWERMODE" Value="0" Before="InstallInitialize" Sequence="execute">NOT POWERMODE</SetProperty>
      
        <UI Id="WixUI_MyMondo">

          <Dialog Id="UserOptionsDialog" Width="370" Height="270" Title="Dialog Title">
            <Control Id="TextLine2" Type="Text" X="50" Y="30" Width="250" Height="55" Text="Please choose the values for each of the following options (This can be skipped if typical options suffice)" TabSkip="yes" Transparent="yes" />
            <Control Id="heapSizeLabel" Type="Text" X="50" Y="80" Height="17" Width="55" Transparent="yes" Text="Heap Size:" />
            <Control Id="ComboBoxMain" Type="ComboBox" X="100" Y="79" Width="150" Height="20" Property="HEAPSIZEVALUE" >
              <ComboBox Property="HEAPSIZEVALUE">
                <ListItem Value="-Xms1024m" />
                <ListItem Value="-Xms2048m" />
                <ListItem Value="-Xms4096m" />
              </ComboBox>
            </Control>
            <Control Id="PowerMode" Type="CheckBox" X="50" Y="100"
                         Width="290" Height="17" Property="POWERMODE"
                         CheckBoxValue="[POWERMODE]"
                         Text="Power (Allow device to sleep)" />
            <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
              <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
            </Control>

            <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="Next" />
            <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="Back" />

          </Dialog>

Here is my registry Registry

My installer Installer

As you can see my Heap_size field is read properly from the registry and shown to the user but for some reason the checbox is always shown as selected.

I went through the logs also and I see that the value is read properly from the registry

MSI (c) (08:24) [11:28:01:194]: PROPERTY CHANGE: Modifying POWERMODE property. Its current value is '1'. Its new value: '0'.

Upvotes: 0

Views: 164

Answers (1)

Christopher Painter
Christopher Painter

Reputation: 55620

In Windows Installer, the CheckBoxValue field is the value of the property when the checkbox is selected not the property itself. When it's not selected it's null. So change it to CheckBoxValue="1".

Where it says Property="POWERMODE" this is the property that will control the checkbox. If it matches the value of CheckBoxValue then it'll be checked. If it's null it won't.

There is a wierd UI bug (feature?) in MSI that if you don't give CheckBoxValue a value then the control can't be checked and unchecked.

https://learn.microsoft.com/en-us/windows/win32/msi/checkbox-table

Remarks

If the check box is selected, then the corresponding property is set to the specified value. If there is no value specified or this table does not exist, then the property is set to its original value when the check box is selected. If the original value is null, the property is set to "1".

By the above logic an unspecified value causes the uncheck to set the property to 1 which then gets interpreted as checked causing the deadlock.

Upvotes: 1

Related Questions