有关.NET应用程序使用ClickOnce安装的,是否有任何的方式来运行在卸载过程中的自定义动作。

具体地讲,我需要删除几个应用程序相关的文件(我第一次运行中创建)和在卸载过程调用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的卸载注册表项,这是你的ClickOnce应用程序访问。

,该特定位置是 “HKEY_CURRENT_USER \ SOFTWARE \微软\的Windows \ CurrentVersion \卸载”

您将不得不寻找与你的应用程序的显示名称的关键。

然后可以包住正常卸载动作,

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();
        }
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top