卸载时使用Installer类实现的自定义操作不起作用

我通过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。谢谢。

xw7932 回答:卸载时使用Installer类实现的自定义操作不起作用

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169207.html

大家都在问