during the installation of my program I want to set values in the registry under a specific key which already exists with a value I need to reset on uninstallation and also I need the old value in my program. I tried to solve this with custom actions:
protected override void OnBeforeInstall(IDictionary savedState) {
var originalCommand = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\myKey\Shell\Open\Command", null, "");
Registry.SetValue(@"HKEY_CURRENT_USER\Software\myProgram\OriginalCommand", null, originalCommand);
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\myKey\Shell\Open\Command", null, "new value");
base.OnBeforeInstall(savedState);
}
protected override void OnAfterRollback(IDictionary savedState) {
ResetRegistryEntries();
base.OnAfterRollback(savedState);
}
protected override void OnAfterUninstall(IDictionary savedState) {
ResetRegistryEntries();
base.OnAfterUninstall(savedState);
}
private void ResetRegistryEntries() {
var originalCommand = Registry.GetValue(@"HKEY_CURRENT_USER\Software\myProgram\OriginalCommand", null, "");
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\myKey\Shell\Open\Command", null, originalCommand);
}
There are two strange things now.. first: If I install via visual studio (right click on my setup project and install) everything works fine.. my new value is set and the old value is also set on my "backup" registry key.. and when I uninstall everything is reset as it should. But.. if I install via the created .msi file the old value isnt set on my backup registry key.. but the new value is.. and the very stange thing.. when I uninstall everything is reset.. I wonder why and from where.