Uninstall a application during installation not working

后端 未结 3 989
时光取名叫无心
时光取名叫无心 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)

提交回复
热议问题