我通过System.Configuration.Install.Installer
类在WPF应用程序中实现了安装程序。我想在卸载应用程序时删除我的应用程序添加的registryKey,因此我将以下内容写为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
{
}
}
}
}
但是它不起作用。实际上,我写的任何东西,无论内容如何,似乎都没有被调用。
我确认确实调用了Uninstall方法,并通过一些代码进行了测试,例如
MessageBox.Show("uninstalled")
。
我该怎么办?我觉得我应该找到其他不使用.dll
的方式。我使用Visual Studio2017。谢谢。