对于使用 ClickOnce 安装的 .NET 应用程序,是否有任何方法可以在卸载过程中运行自定义操作。
具体来说,我需要删除一些与应用程序相关的文件(我在第一次运行时创建的)并在卸载过程中调用 Web 服务。
有任何想法吗?
对于使用 ClickOnce 安装的 .NET 应用程序,是否有任何方法可以在卸载过程中运行自定义操作。
具体来说,我需要删除一些与应用程序相关的文件(我在第一次运行时创建的)并在卸载过程中调用 Web 服务。
有任何想法吗?
ClickOnce 本身无法做到这一点,但您可以创建一个标准的 Setup.exe 引导程序,用于安装 ClickOnce 应用程序并具有自定义卸载操作。
请注意,这会在“添加/删除”程序中创建两个条目,因此您需要隐藏其中一个条目(clickonce 应用程序)。
然后,您的最后一个问题将是 clickonce 没有“静默卸载”选项,因此您可以执行以下操作:
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "taskkill /f /im [your app process name]*"
objShell.Run "[your app uninstall key]"
Do Until Success = True
Success = objShell.AppActivate("[your window title]")
Wscript.Sleep 200
Loop
objShell.SendKeys "OK"
(在这里找到)
ClickOnce 会在 HKEY_CURRENT_USER 中安装一个 Uninstall 注册表项,您的 ClickOnce 应用程序可以访问该注册表项。
具体位置为“HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”
您必须使用应用程序的 DisplayName 搜索密钥。
然后您可以包装正常的卸载操作,
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();
}
}
}