Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

c# - Uninstall a application during installation not working

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).

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.

uninstallation method:

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 "";
        }

Update:After using WIX MSI Installer

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>

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.

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

Update 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>

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...