11

I am looking for a way to detect if WebView2 runtime is installed on the clients machines so that i can display using the old ie browser instead if they don't have it installed. I am using VB.NET.

Thanks

Tom Knevitt
  • 129
  • 1
  • 1
  • 7

4 Answers4

9

You can refer to this doc about how to check if the WebView2 Runtime is already installed. To verify, complete one of the following actions:

  • Inspect if the pv (REG_SZ) regkey exists and is not null or empty. Find pv (REG_SZ) at the following location:

     HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}
    

    VB.NET code to check pv regkey:

     Dim readValue = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}", "pv", Nothing)
     If readValue Is Nothing Then
         'Key doesn't exist
     Else
         'Key existed, check value
     End If
    
  • Run GetAvailableCoreWebView2BrowserVersionString and ensure the versionInfo is NULL.

    It uses C++ in the doc. For VB.NET, the corresponding method is GetAvailableBrowserVersionString(String). You can refer to the doc about how to use it in VB.NET.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • Thanks you very much, the first part worked perfects, altough i couldnt get the second part to work. Not sure if this is required though as the first bit works. – Tom Knevitt Nov 09 '20 at 13:16
  • You're welcome. You only need to use one of the parts. – Yu Zhou Nov 10 '20 at 02:07
8

I have implemented a working code example in C#. It uses the method CoreWebView2Environment.GetAvailableBrowserVersionString() to get the version.

I have tested with the regkey solution, but it did not work with Edge Chromium Beta, Dev or Canary. It only work when WebView2 runtime were installed.

public static class WebView2Install
{
    public static InstallInfo GetInfo()
    {
        var version = GetWebView2Version();

        return new InstallInfo(version);
    }

    private static string GetWebView2Version()
    {
        try
        {
            return CoreWebView2Environment.GetAvailableBrowserVersionString();
        }
        catch (Exception) { return ""; }
    }
}

public class InstallInfo
{
    public InstallInfo(string version) => (Version) = (version);

    public string Version { get; }

    public InstallType InstallType => Version switch
    {
            var version when version.Contains("dev") => InstallType.EdgeChromiumDev,
            var version when version.Contains("beta") => InstallType.EdgeChromiumBeta,
            var version when version.Contains("canary") => InstallType.EdgeChromiumCanary,
            var version when !string.IsNullOrEmpty(version) => InstallType.WebView2,
            _ => InstallType.NotInstalled
    };
}

public enum InstallType
{
    WebView2, EdgeChromiumBeta, EdgeChromiumCanary, EdgeChromiumDev, NotInstalled
}

I also have made a WPF application that uses WebView2 on GitHub, it also show you the usage of the above code.

KioskBrowser (GitHub)

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Morten Brudvik
  • 439
  • 5
  • 10
  • You say the regkey solution did not work for you. Did you check both registry keys as per docs? Or just one of them? (The accepted solution here is missing the other key.) – Kissaki Aug 04 '22 at 07:17
5

I have come up with the following implementation. (Sorry it is in C#)

private bool WebViewIsInstalled()
{
  string regKey = @"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients";
  using (RegistryKey edgeKey = Registry.LocalMachine.OpenSubKey(regKey))
  {
    if (edgeKey != null)
    {
      string[] productKeys = edgeKey.GetSubKeyNames();
      if (productKeys.Any())
      {
        return true;
      }
    }
  }

  return false;
}
Kingpin
  • 1,067
  • 2
  • 14
  • 34
2

The "best answer" is not the proper answer any more. When newer MS-Edge versions (for example: 97.0.1072.55) are installed the key

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}

is not created, but another key under HKEY_CURRENT_USER is created:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}

So, checking the key under HKEY_LOCAL_MACHINE is not enough, HKEY_CURRENT_USER should be checked too.

75ntamas
  • 123
  • 5