Uninstall a application during installation not working

后端 未结 3 986
时光取名叫无心
时光取名叫无心 2020-12-21 03:59

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

相关标签:
3条回答
  • 2020-12-21 04:48

    There is a option to uninstall the application using Windows Management Instrumentation (WMI). Using the ManagementObjectSearcher get the application needs to be Uninstalled and use the ManagementObject Uninstall method to uninstall the application.

    ManagementObjectSearcher mos = new ManagementObjectSearcher(
          "SELECT * FROM Win32_Product WHERE Name = '" + ProgramName + "'");
        foreach (ManagementObject mo in mos.Get())
        {
            try
            {
                if (mo["Name"].ToString() == ProgramName)
                {
                    object hr = mo.InvokeMethod("Uninstall", null);
                    return (bool)hr;
                }
            }
            catch (Exception ex)
            {
    
            }
        }
    

    Detailed explanation given in Uninstalling applications programmatically (with WMI)

    0 讨论(0)
  • 2020-12-21 04:56

    sorry to be the one with the bad news... but:

    when installing / uninstalling a program from any modern windows-based machine - there is no way to start more then 1 instance of the installation wizard (in short: the msiExec)

    that is why it works great on other parts of your project - because no calls for the msiExec are made at those points

    and now for the good news: you can send the unistall command with a delay, or even better - start a timer that asks every X seconds if the installation is over. when the installer will complete, you will be able to make the unistall commands. something like this:

            timer = new System.Timers.Timer(2 * 1000) { Enabled = true };
    
            timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
            {
    
            }
    
            timer.Start(); // finally, call the timer
    
    0 讨论(0)
  • 2020-12-21 05:05

    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.

    0 讨论(0)
提交回复
热议问题