Registry entry that was removed on install not bei

2019-08-16 06:46发布

问题:

I have a Wix script with a RemoveRegistryValue element. It correctly removes the registry value when I install the product (provided I run with elevated privilege, which I am now). However, when I uninstall the product the registry value is not replaced. If I wanted the value removed and never to be seen again I could have just gone into regedit and removed it. The whole idea of putting the removal in a Windows Installer package is so that I could uninstall the package and put everything back as it was should I need to. However this is not happening.

<RemoveRegistryValue Id='ShowLnk' Root ='HKLM' 
       Key='SOFTWARE\Classes\Lnkfile' Name ='NeverShowExt' /> 

On installation the value is removed (causing shortcuts to display their .lnk extension if you must know what it does). On uninstallation the registry value is not replaced (causing shortcuts to display their .lnk extensions forever, which is likely a good thing, but not relevant to this discussion).

How do I get the registry value back into the registry on uninstalling my product?

I've followed on now with another question here...Getting a custom action to run on install and uninstall

回答1:

On uninstall, Windows Installer only "undoes" things that it actually created on the local machine during installation.

"Side effects" like removal of registry keys/values and files will not be undone during uninstall (though when a rollback happens, these will be undone as expected).

To support your scenario you have to do backup and restore of the registry value yourself:

On install:

  • Use RegistrySearch to get the existing value of 'NeverShowExt'. You may need to set Win64="yes", I'm not sure about that.

  • Store a backup of the value in your apps registry key (HKLM\Software\[Manufacturer]\YourProductKey).

On uninstall:

  • Use RegistrySearch to get the backup value from your apps registry key.
  • Create a deferred custom action that writes the registry value back to its original location. There is no declarative "WiX way" to write something to the registry upon uninstall.


标签: windows wix