Reputation: 164
I have a wix based setup (MSI) and want to protect user settings, which are stored in the registry under HKCU, when updating my application.
For now, when I upgrade my application every registry value will be overwritten, so that the user has to set his settings again.
I also want to remove all settings, when uninstall the whole application.
Can anybody help?
My code looks like this:
<Component Id="REGISTRY_ReConnect" Guid="$(var.GUID_REGISTRY_ReConnect)">
<RegistryValue Id="_REGISTRY_ReConnect" Root="HKCU" Key="Software\exampleX\MBCA" Name="ReConnect" Value="1" Type="integer" KeyPath="yes" />
</Component>
Upvotes: 0
Views: 655
Reputation: 3147
For each of the settings in registry do the following:
Define a Property containing the default value of the setting.
Define a RegistrySearch which will extract a value of the setting from registry and put it into another Property.
Use SetProperty to (conditionally) upgrade the value of first property with the value extracted from the registry.
In your Component/RegistryValue/@Value use the value of the first property instead of explicit value.
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="MyProduct" Language="1033" Version="1.1.0.0" Manufacturer="MyCompany" UpgradeCode="81a34cee-f0da-4135-9f37-53e02e4b450a">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perUser" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" />
<Feature Id="ProductFeature" Title="MyProduct1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolde">
<Directory Id="INSTALLFOLDER" Name="MyProduct" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<Property Id="ReConnect" Value="1" />
<Property Id="OLDRECONNECT">
<RegistrySearch Id="ReConnectSearch" Root="HKCU" Key="Software\exampleX\MBCA" Name="ReConnect" Type="raw" />
</Property>
<SetProperty Id="ReConnect" Value="[OLDRECONNECT]" After="AppSearch">OLDRECONNECT</SetProperty>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="REGISTRY_ReConnect">
<RegistryValue Id="_REGISTRY_ReConnect" Root="HKCU" Key="Software\exampleX\MBCA" Name="ReConnect" Value="[ReConnect]" Type="integer" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Upvotes: 2