Uninstall the existing WPF application installed on windows when reinstalling

The project I’m currently working on is a could base .net core react web application, a web version of the desktop application the customer has now. We have 3 setups (MSI installer) written using WPF. In order to enable the web version we have to activate it first on the customer’s windows machines.

Customers can activate and connect with the web version first time. and then we have updates to be installed from time to time using the same setup. once user runs the installer setup. it will install all 2 other setups and will open the last setup, let’s say it as connector.

The issue was the connector setup didn’t open automatically when install updates. so I had to uninstall it from windows by the code before install updates.

This is how I achieved it.

  • First, we should know the name of the app, you can find it easily from the setup project (in my case we have a WIX project).
  • Below are the methods we have to implement and it will uninstall the application from windows add/remove programmes.
  • Please note that when we retrieve the Uninstall string, I have considered both windows 32bit and 64bit versions in the registry paths.
  • The Uninstall string would looks like this – “msiexec.exe /x 0C2B6785508321B44A7EB21A23EFB117”
    private void UninstallConnectorSetup()
    {

      var uninstallString = GetUninstallString("<app name>");
      Process process = new Process();
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.RedirectStandardError = true;
      process.StartInfo.FileName = "msiexec.exe";
      process.StartInfo.Arguments = uninstallString;
      process.Start();
    }

    private string GetUninstallString(string msiName)
    {
      string uninstallString = string.Empty;
      try
      {
        string path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products";
        RegistryKey key = Registry.LocalMachine.OpenSubKey(path);
        if (key == null)
        {
          key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).
          OpenSubKey(path);
        }
        foreach (string tempKeyName in key.GetSubKeyNames())
        {
          RegistryKey tempKey = key.OpenSubKey(tempKeyName + "\\InstallProperties");
          if (tempKey != null)
          {
            if (string.Equals(Convert.ToString(tempKey.GetValue("DisplayName")), msiName, StringComparison
            .CurrentCultureIgnoreCase))
            {
              uninstallString = Convert.ToString(tempKey.GetValue("UninstallString"));
              uninstallString = uninstallString.Replace("/I", "/X");
              uninstallString = uninstallString.Replace("MsiExec.exe", "").Trim();
              uninstallString += " /quiet /qn";
              break;
            }
          }
        }
        return uninstallString;
      }

      catch (Exception ex)
      {
        throw new ApplicationException(ex.Message);
      }
    }

Show WebBrowser content within WPF devexpress user control

Sometimes one single property will be enough to change the whole feature in a meaning full manner. One of recent project I am working have a feature to show google map within WPF user control which is a devexpress user control. I’m going to describe an issue i got from that user control.

Feature:

  • We have a User Control which has a web browser control within that, which is rendering google map online.
  • There is a Dispatcher main user control which contains few other windows including the above map control. Each user control can be collapsed, pinned, dragged within the main view.
  • I’m using DockPanel to arrange all the user controls. And have DockLayoutManager within the DockPanel. I placed my user control inside a LayoutPanel in AutoHideGroup.

Problem:

  • When I drag the map user control, it shows it’s background color by hiding the map.

Solution:

  • The WPF WebBrowser control hosts the native WebBrowser ActiveX control internally and therefore, cannot work with certain WPF features such as the window transparency. We should set the EnableWin32Compatibility property at the DockLayoutManager level to true to disable transparency for DockLayoutManager’s panel.