Question

I've created an installer with WiX and am trying to preserve an existing DWORD registry entry during a repair installation of my product. To store the existing values, I am using the following WiX fragment;

<Property Id="PreserveMySetting" Secure="yes">
  <RegistrySearch Id="FindExistingMySetting"
                  Root="HKLM"
                  Key="Software\!(loc.ProductManufacturer)\!(loc.ProductName)"
                  Name="MySetting"
                  Type="raw"
                  Win64="no" />
</Property>

I then set this later on using a component driven by the saved value.

The problem is, the registry search returns the DWORD as a "Formatted" string, e.g.;

#1

Instead of just

1

This means that when my component sets the registry entry, it is created as a REG_SZ with the value "#1", even though I've indicated that it should be an integer;

<Component Id="MySettingKey"
    Guid="{76C4B14C-14BC-42E1-91F0-75C9F2A20EC8}">
    <RegistryValue Id="MySetting"
        Action="write"
        Name="MySetting"
        Value="[PreserveMySetting]"
        Type="integer"
        KeyPath="yes"
        Key="Software\!(loc.ProductManufacturer)\!(loc.ProductName)"
        Root="HKMU"/>
</Component>

Is there any way to get the actual registry value for use by the component?

Was it helpful?

Solution

This is going to sound backwards, but if you change the Type attribute to string it'll work. The reason is clear when you look at your MSI's Registry table using ORCA.

When you select integer WiX author's "#[PRESERVEMYSETTING]" and when you select string it author's [PRESERVEMYSETTING]. Since PRESERVEMYSETTING is already #1 you want it to be #1 not ##1.

<Component Id="MySettingKey" 
    Guid="{76C4B14C-14BC-42E1-91F0-75C9F2A20EC8}">
    <RegistryValue Id="MySetting"
        Action="write"
        Name="MySetting"
        Value="[PRESERVEMYSETTING]" <!-- Secure Properties are PUBLIC properties -->
        Type="string"
        KeyPath="yes"
        Key="Software\!(loc.ProductManufacturer)\!(loc.ProductName)"
        Root="HKMU"/>
</Component>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top