在安装过程中卸载应用程序不起作用 [英] Uninstall a application during installation not working

查看:28
本文介绍了在安装过程中卸载应用程序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C# 开发 WPF 应用程序.目前我的msi在机器上安装当前的应用程序.我需要在安装新的一个(msi)的过程中卸载现有版本的两个支持应用程序.

I am developing WPF application in C#. Currently my msi install the current application in machine.I need to uninstall two supporting application of existing version during the installation of new one(msi).

我编写了以编程方式卸载应用程序的代码,当我调用 installer.cs 中的应用程序卸载方法时,这不起作用.当我从项目的其他部分调用时,相同的方法成功卸载了两个应用程序除了 installer.cs.

I written code to uninstall application programmatically and this does not work when i call the application uninstallation method in installer.cs.The same method uninstall the two application successfully when i call from other part of project other than installer.cs.

卸载方法:

public static string GetUninstallCommandFor(string productDisplayName)
        {
            RegistryKey localMachine = Registry.LocalMachine;
            string productsRoot = @"SOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products";
            RegistryKey products = localMachine.OpenSubKey(productsRoot);
            string[] productFolders = products.GetSubKeyNames();

            foreach (string p in productFolders)
            {
                RegistryKey installProperties = products.OpenSubKey(p + @"InstallProperties");
                if (installProperties != null)
                {
                    string displayName = (string)installProperties.GetValue("DisplayName");
                    if ((displayName != null) && (displayName.Contains(productDisplayName)))
                    {                      
                        string fileName = "MsiExec.exe";
                        string arguments = "/x{4F6C6BAE-EDDC-458B-A50F-8902DF730CED}";

                        ProcessStartInfo psi = new ProcessStartInfo(fileName, arguments)
                        {
                            CreateNoWindow = true,
                            UseShellExecute = false,
                            RedirectStandardOutput = true
                        };

                        Process process = Process.Start(psi);

                        process.WaitForExit();

                        return uninstallCommand;
                    }
                }
            }

            return "";
        }

更新:使用 WIX MSI 安装程序后

我已经在 WIX 中创建了 CustomAction 项目,还使用 ​​WIX 创建了 Setup 项目.请参阅我的 Product.wxs

I have created the CustomAction project in WIX, also created the Setup project using WIX.Please see my Product.wxs

 <InstallExecuteSequence>
      <Custom Action='ShowCustomActionCustomAction' After='InstallFinalize'>NOT Installed</Custom>
    </InstallExecuteSequence>

我在 CustomAction.cs 中有卸载 3 个应用程序的代码.当我运行我的 WIX MSI 时,它安装新应用程序并卸载第一个应用程序.其余两个应用程序没有卸载,我注意到成功卸载第一个应用程序后应用程序界面关闭,什么也没有发生.

I have the code to uninstall 3 application in CustomAction.cs.When i run my WIX MSI,it install the new application and uninstall the first application.The remaining two application are not uninstalled,i noticed that after successful uninstall of first application the UI closes and nothing happens.

你能告诉我如何在我的 WIX MSI 安装过程中卸载 3 应用程序吗?

Can you tell me how to uninstall the 3 application during the installation of my WIX MSI.

更新 2:

<Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
    <Upgrade Id="89CF8BE7-05EE-4C7E-9EFC-0249DD260EBB">
      <UpgradeVersion
         Minimum="1.0.0.0" Maximum="99.0.0.0"
         Property="PREVIOUSVERSIONSINSTALLED"
         IncludeMinimum="yes" IncludeMaximum="no" />
    </Upgrade>
<InstallExecuteSequence>     
      <RemoveExistingProducts Before="InstallFinalize" />
    </InstallExecuteSequence>
  </Product>

product.wxs中的上述设置是卸载之前的版本安装新的.同时我还需要卸载另外两个依赖应用.如何使用wix installer卸载依赖应用.

the above settings in product.wxs is uninstalling the previous version and install the new one.Along with this i need to uninstall another two dependency application also.How to uninstall the dependency application using wix installer.

谁能帮我在安装我的新 wix msi 之前检查机器中已安装的应用程序并卸载它.

Can any one help me how to check the installed application in the machine and uninstall that before installation of my new wix msi.

推荐答案

MSI 中有一个互斥锁可以防止并发安装/卸载.一切都必须在单个安装程序的上下文中发生.也就是说,这样做的方法是将行创作到升级表中,以教 FindRelatedProducts 和 RemoveExistingProducts 删除额外安装的 MSI.

There is a mutex in MSI that prevents concurrent installation / uninstalls. Everything has to happen within the context of a single installer. That said, the way to do that is to author rows into the Upgrade table to teach FindRelatedProducts and RemoveExistingProducts to remove the additional installed MSIs.

您没有提到您使用什么来创建您的 MSI,所以我无法向您展示如何做到这一点.

You don't mention what you are using to create your MSI so I can't show you how to do that.

您现在已经提到您正在使用 VDPROJ.此工具不支持创作您正在尝试执行的操作.我的建议是使用 Windows Installer XML (WiX) 进行重构并编写多个升级元素以删除各种产品.

You've now mentioned that you are using VDPROJ. This tool doesn't support authoring what you are trying to do. My suggestion is to refactor using Windows Installer XML (WiX) and author multiple Upgrade elements to remove the various products.

这篇关于在安装过程中卸载应用程序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆