wpf get ie browser version

WebBrowser rendering

As shown in the figure below, ShDocVw and the following are the contents of WebBrowser, and Browser UI does not belong to WebBrowser.
@import "ie.png"
Many softwares have embedded IE's WebBrowser control (that is, MSHTML.dll) to display web pages. When the user's machine is upgraded to a certain IE version, the WebBrowser control will also be upgraded to the corresponding version. The rendering engine corresponding to Ie. In order to ensure that the WebBrowser control can work properly, the WebBrowser control of different IE versions uses the rendering mode of IE7 by default.
Modify ie
- use the registry to detect whether ie is installed, and get the version number of ie.

RegistryKey mainKey = Microsoft.Win32.Registry.LocalMachine;
RegistryKey subKey = mainKey.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer");
if (subKey == null)
{
    Console.WriteLine("未安装ie");
    return;
}else
{
    object value = subKey.GetValue("Version");
}

Get the major version number below.

char[] separator = {'.'};
var mywords = value.Split(separator);
var mainVersion = mywords[0];

The version number obtained from the registry on my machine is lower than the version number on ie, so it can't be done this way.

The solution corresponding to the ie version number in wpf:

  • Use the Version property of webBrowser in winForms
var version = new WebBrowser().Version.Major;

The version number obtained at this point is the same as seen in ie.

  • Another way to get a registry
public static string GetVersion()
{
    RegistryKey browserKeys;
    //on 64bit the browsers are in a different location
    browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet\IEXPLORE.EXE\shell\open\command");
    if (browserKeys == null)
        browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet\IEXPLORE.EXE\shell\open\command");
    if (browserKeys != null)
    {
        var filepath = browserKeys.GetValue(null)?.ToString();
        if (!string.IsNullOrEmpty(filepath))
        {
            return FileVersionInfo.GetVersionInfo(filepath)?.FileVersion;
        }
    }
    return null;
}

Use the method mentioned at the beginning to get the major version number

char[] separator = {'.'};
var mywords = GetVersion()?.Split(separator);
if(mywords != null)
    var mainVersion = mywords[0];

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324402167&siteId=291194637