【问题标题】:Uninstall applications in the installation and deployment process在安装部署过程中卸载应用程序
【发布时间】:2016-01-03 17:31:49
【问题描述】:

我正在创建一个应用程序,我要求在安装过程中应用程序卸载一些其他已安装的程序,所以我首先要做的是创建一个控制台应用程序来卸载程序,直到有工作,我添加这个控制台应用程序作为设置和构建解决方案中的自定义操作,但在安装时卸载程序不起作用。

对不起我的英语不好:)。

我使用以下代码进行卸载。

       string UninstallCommandString = "/x {0} /qn";
        Process process = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo();
        process.StartInfo = startInfo;

        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardError = true;

        startInfo.FileName = "msiexec.exe";
        startInfo.Arguments = string.Format(UninstallCommandString, "{CCB85747-267D-45C6-AC32-7979ADFCD2D8}");
        process.Start();
        process.WaitForExit();

        string UninstallCommandString2 = "/x {0} /qn";
        Process process2 = new Process();
        ProcessStartInfo startInfo2 = new ProcessStartInfo();
        process2.StartInfo = startInfo2;

        startInfo2.UseShellExecute = false;
        startInfo2.RedirectStandardError = true;

        startInfo2.FileName = "msiexec.exe";
        startInfo2.Arguments = string.Format(UninstallCommandString2, "{7A8A8C03-6BEA-45B4-BAD9-EBC5790A037A}");
        process2.Start();
        process2.WaitForExit();


        string UninstallCommandString3 = "/x {0} /qn";
        Process process3 = new Process();
        ProcessStartInfo startInfo3 = new ProcessStartInfo();
        process3.StartInfo = startInfo3;

        startInfo3.UseShellExecute = false;
        startInfo3.RedirectStandardError = true;

        startInfo3.FileName = "msiexec.exe";
        startInfo3.Arguments = string.Format(UninstallCommandString3, "{6AFDD6D0-3F33-45F0-B058-677F2080AE22}");
        process3.Start();
        process3.WaitForExit();

        string UninstallCommandString4 = "/x {0} /qn";
        Process process4 = new Process();
        ProcessStartInfo startInfo4 = new ProcessStartInfo();
        process4.StartInfo = startInfo4;

        startInfo4.UseShellExecute = false;
        startInfo4.RedirectStandardError = true;

        startInfo4.FileName = "msiexec.exe";
        startInfo4.Arguments = string.Format(UninstallCommandString4, "{ACC5E4C6-B4D2-4227-B577-95D511C05A6E}");
        process4.Start();
        process4.WaitForExit();

【问题讨论】:

    标签: c# uninstallation setup-project windows-installer


    【解决方案1】:

    您无法通过自定义操作进行安装或卸载,这尤其适用于 VS 设置项目。一次只允许一个 MSI 操作。

    通常您会通过重大升级来执行此操作,即 VS 设置项目中的 RemovePreviousVersions,但 VS 不支持升级设置的当前 UpgradeCode 之外的任何内容。另一个工具(如 Wix)可以让您列出一堆升级代码,您的安装将自动卸载相关产品。

    所以这取决于您的工作流程要求。您可以将您的安装程序压缩到一个运行卸载的自解压 exe 中,然后运行您的 setup.exe(如果您有安装的先决条件)或只安装您的 MSI。或者您可以使用 MSI 编辑器工具(例如 Orca)将这些 MSI 产品的 UpgradeCodes 添加到您的 MSI 的升级表中,并且您已经构建了 RemovePreviousVersions 升级,然后它将卸载它们。答案不多,但是您正在尝试执行 Windows Installer 不支持的操作(来自自定义操作的 MSI 操作)并且 VS 不支持(卸载其他产品的升级)。

    【讨论】:

    • 是的,感谢您的回复,我明白了,我得到了解决方案,而且比我想象的要容易,有两种方法可以做到。 1. InstallShield 自定义操作,初始化后(对话框前):如果我在这部分运行我的代码,因为它在安装前运行,所以运行良好,问题是它不适用于远程部署和静默安装。 2. InstallShield升级路径:只添加你要卸载的.msi程序文件,完美运行!
    猜你喜欢
    • 2012-01-02
    • 2019-12-13
    • 2012-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    相关资源
    最近更新 更多