I implemented installer to my WPF app by System.Configuration.Install.Installer
class. I wanted to remove registryKey added by my app when uninstalling it, so I wrote follwing as a part of CustomAction.dll:
using System;
namespace CustomAction
{
[System.ComponentModel.RunInstaller(true)]
public class ActionSetting : System.Configuration.Install.Installer
{
public override void Uninstall(System.Collections.IDictionary savedState)
{
var name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
RemoveKey(name);
base.Uninstall(savedState);
}
private void RemoveKey(string Key)
{
try
{
Microsoft.Win32.RegistryKey regkey =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
@"Software\Microsoft\Windows\CurrentVersion\Run", true);
regkey.DeleteValue(Key, false);
regkey.Close();
}
catch
{
}
}
}
}
But it doesn't work. In practice, anything I wrote, regardless of the contents it doesn't seems to be called.
I confirmed Uninstall method is definitely called, testing by some code like
MessageBox.Show("uninstalled")
.
What should I do? I feel like I should find other way not using .dll
. I use Visual Studio 2017. thanks.