.net - 卸载时的自定义操作(单击一次)- 在 .NET 中

标签 .net clickonce uninstallation custom-action

对于使用 ClickOnce 安装的 .NET 应用程序,是否有任何方法可以在卸载过程中运行自定义操作。

具体来说,我需要删除一些与应用程序相关的文件(我在第一次运行时创建的文件)并在卸载过程中调用 Web 服务。

有什么想法吗?

最佳答案

ClickOnce 在 HKEY_CURRENT_USER 中安装卸载注册表项,ClickOnce 应用程序可以访问该注册表项。

具体位置为“HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”

您必须使用应用程序的 DisplayName 来搜索 key 。

然后您可以包装正常的卸载操作,

string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
Microsoft.Win32.RegistryKey uninstallKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(registryKey);
if (uninstallKey != null)
{
    foreach (String a in uninstallKey.GetSubKeyNames())
    {
        Microsoft.Win32.RegistryKey subkey = uninstallKey.OpenSubKey(a, true);
        // Found the Uninstall key for this app.
        if (subkey.GetValue("DisplayName").Equals("AppDisplayName"))
        {
            string uninstallString = subkey.GetValue("UninstallString").ToString();

            // Wrap uninstall string with my own command
            // In this case a reg delete command to remove a reg key.
            string newUninstallString = "cmd /c \"" + uninstallString +
                " & reg delete HKEY_CURRENT_USER\\SOFTWARE\\CLASSES\\mykeyv" +
                MYAPP_VERSION + " /f\"";
            subkey.SetValue("UninstallString", newUninstallString);
            subkey.Close();
        }
    }
}

关于.net - 卸载时的自定义操作(单击一次)- 在 .NET 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1163149/

相关文章:

windows - 如何以编程方式在 Windows 中查找已安装应用程序的安装位置

c++ - 如何在 VC++ 中禁用 Windows TCP/IP 堆栈 [以编程方式]

windows-installer - 不存在的 GUID 的静默 MSI 卸载

c# - 在不知道 T 的情况下将泛型类型指定为参数参数

c# - 使用 "very very"大数组

.net - 将经典 ASP 应用程序迁移到 ASP.NET

c# - 可选参数的默认值必须是静态的吗?

deployment - 从 KB 修补程序中提取产品代码以在 Bootstrap 中使用

javascript - window.location 在 Internet Explorer 中的 AJAX 请求后不起作用

visual-studio-2010 - 来自同一位置的 Visual Studio 2010 ClickOnce 先决条件