gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 20:12:39 26 4
gpt4 key购买 nike

对于使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com