0
votes

I have a simple wix application which modifies an existing registry value. During uninstallation the registry should be set to the previous/original value. Therefore i'm storing these existing values into a temporary registry.

I can read these temporary registry value into a property, But how do i set this property to the registry during uninstallation?

This is my Property which will read the original values from the temporary registry:

<Property Id="TEMPVALUE" Secure="yes">
  <RegistrySearch Id="FindExistingMySetting"
                  Root="HKLM"
                  Key="Software\SampleApp"
                  Name="TempSampleKey"
                  Type="raw"/>
</Property>

So how should I use this "TEMPVALUE" property to set the registry during uninstall. I think some kind of custom action might be required. I'm new to this concept, so a sample would be really helpful.

1

1 Answers

0
votes

I did this by using a custom action. I don't think it is possible otherwise since there is no way to install components on uninstall (that I know of).

As an example I have a custom action called "SaveOriginalRegistryValue" to save the original value with the registry key name having "_Original" appended to the end of its name.

And then I another custom action called "RestoreOriginalRegistryValue" which puts the original key back and then deletes the "_Original" key from the registry.

In the wix installer definition I have

<CustomAction Id="CA_SaveOriginalRegistrySettings" BinaryKey="ClientCustomActionsDLL" DllEntry="SaveOriginalRegistrySettings" Execute="deferred" />
<CustomAction Id="CA_RestoreOriginalRegistrySettings" BinaryKey="ClientCustomActionsDLL" DllEntry="RestoreOriginalRegistrySettings" Execute="deferred" />

<InstallExecuteSequence>
    <Custom Action="CA_SaveOriginalRegistrySettings" After="WriteRegistryValues">NOT UPGRADINGPRODUCTCODE AND NOT REMOVE~="ALL" AND NOT WIX_UPGRADE_DETECTED</Custom>
    <Custom Action="CA_RestoreOriginalRegistrySettings" After="RemoveRegistryValues">NOT UPGRADINGPRODUCTCODE AND REMOVE~="ALL"</Custom>
</InstallExecuteSequence>

So the Saving custom action will when this is the first time installing the product and not on upgrades.

The restoring custom action will only run when completely removing the product and not when we're removing the older version on an upgrade.