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