Search code examples
windowsinstallationwixwix3

How do you conditionally set a property or RegistryValue in WiX?


I have a Wix Toolset project with a component such as the one below, where MYLANGUAGE is a public property that can be set when installing the product:

      <Component Id='language_reg' Guid='*' Permanent='yes'>
        <Condition>MYLANGUAGE</Condition>
        <RegistryValue Type='string' Root='HKLM' Key='Software\MyCompany\MyProduct' Name='language'
        Value='[MYLANGUAGE]' KeyPath='yes' />
      </Component>

Now I am upgrading this software package from 32-bit 64-bit. The key above from the existing 32-bit versions of my software is stored under HKLM\Software\WOW6432Node\MyCompany\MyProduct because of WOW64.

After an upgrade to a new 64-bit version of the package the upgrade I would like to have the value set in the HKLM\Software\MyCompany\MyProduct key too. The value shall be set like this:

  • If the public property MYLANGUAGE is set when installing then the value of that property shall be stored in HKLM\Software\MyCompany\MyProduct language
  • If the public property MYLANGUAGE is not set and HKLM\Software\MyCompany\MyProduct key doesn't exist and HKLM\Software\WOW6432Node\MyCompany\MyProduct language value is set then I want the value copied from HKLM\Software\WOW6432Node\MyCompany\MyProduct language to HKLM\Software\MyCompany\MyProduct language

How can I do this with WIX Toolset?


Solution

  • This is the WiX remember property pattern but a little more complicated.

    Define property MyLanguageDefault with a default value for MYLANGAUGE

    Use AppSearch/Reglocator (Property/RegistrySearch) to read 64bit value into 64bit temp property.

    Use AppSearch/Reglocator (Property/RegistrySearch) to read 32bit value into 32bit temp property. Use SetProperty custom action to assign 64bit temp property to MYLANGUAGE if MYLANGUAGE is null (maybe they passed it at the command line ) and 64bit temp property is not null

    Use SetProperty custom action to assign 32bit temp property to MYLANGUAGE if MYLANGUAGE is null (maybe they passed it at the command line ) and 32bit temp property is not null

    Use SetProperty custom action to assign MyLanguageDefault to MYLANAGUGE if MYLANGUAGE is null (nothing passed at command line and nothing found in 32bit or 64bit then use default value )

    Display MYLANGUAGE in a dialog if you want them to be able to be able to edit it.

    Use MYLANAGUAGE in a Component/RegistryValue to write the value to the 64bit registry. The component needs to have the Win64 attribute set to yes.

    Please note that MYLANGUAGE also needs to be marked as a Secure Custom Public Property by using the Secure="yes" attribute.