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