tete
tete

Reputation: 4999

WIX: writing a permanent registry key but erase the value when uninstalling

I have such a scenario for our installer project using WIX 3.6: we want to create a registry key in the installation(if this one does not already exist), write a string value with version number. In the uninstallation, we would like to keep this registry key, but erase this string value to empty string. I know I can achieve the "keeping registry key" part by setting it as "Permanent", but I don't know how to make the uninstallation erase the value. Thanks for any help in advance!

Upvotes: 0

Views: 2894

Answers (2)

tete
tete

Reputation: 4999

Like I mentioned on the comment of caveman_dick's answer, I had to add a custom action to do the work. Could't find a way of configuring WIX to do it.

Upvotes: 0

caveman_dick
caveman_dick

Reputation: 6637

Not 100% sure this will work as I haven't done it myself, but might be worth a go.

Firstly create the key with the ForceCreateOnInstall (Permanent shouldn't be required) this will not remove the key on uninstall:

<Component Id="RegistryEntryKey" Guid="PUT-GUID-HERE">
    <RegistryKey Root="HKCU"
                 Key="Software\Microsoft\MyApplicationName"
                 ForceCreateOnInstall="yes">
        <RegistryValue Type="integer" 
                       Name="VersionNumber"                            
                       KeyPath="yes"/>
    </RegistryKey>
</Component>

then just have a second compoment that just writes the version on installation:

<Component Id="RegistryEntryValue" Guid="PUT-GUID-HERE">
    <RegistryKey Root="HKCU"
                 Key="Software\Microsoft\MyApplicationName"
                 Action="write">
        <RegistryValue Type="integer" 
                       Name="VersionNumber" 
                       Value="1.2.35" 
                       KeyPath="yes"/>
    </RegistryKey>
</Component>

That should then just undo the write when you un-install.

Upvotes: 1

Related Questions