C# 获取系统当前IE版本号

C#

浏览数:349

2019-6-14

浏览器-获取IE版本号

读取IE的版本号

 1         /// <summary>
 2         /// 获取IE版本号
 3         /// </summary>
 4         /// <param name="text"></param>
 5         /// <returns></returns>
 6         public static string GetMajorVersion(string text)
 7         {
 8             //通过WebBrowser方案获取版本号
 9             int mainVer = (new WebBrowser()).Version.Major;
10             return mainVer;
11         }    

注册表-获取IE版本号

1. 注册表中,IE的位置:

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer

2. 通过注册表读取IE配置

1     RegistryKey mainKey = Registry.LocalMachine;
2     RegistryKey subKey = mainKey.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer");

3. 获取主版本号(8/9/10 etc.)

 1     /// <summary>
 2     /// IE浏览器版本号帮助类
 3     /// </summary>
 4     public static class IEVersionHelper
 5     {
 6         /// <summary>
 7         /// 获取IE主版本号
 8         /// </summary>
 9         /// <param name="text"></param>
10         /// <returns></returns>
11         public static string GetMajorVersion(string text)
12         {
13             var majorVersion = string.Empty;
14 
15             var detailVersion = GetDetailVersion(text);
16             if (!string.IsNullOrWhiteSpace(detailVersion))
17             {
18                 if (detailVersion.IndexOf(".", StringComparison.Ordinal) is int connectedCharFirstIndex && connectedCharFirstIndex > -1)
19                 {
20                     majorVersion = detailVersion.Substring(0, connectedCharFirstIndex);
21                 }
22                 else
23                 {
24                     majorVersion = detailVersion;
25                 }
26             }
27 
28             return majorVersion;
29         }
30 
31         /// <summary>
32         /// 获取IE详细版本号
33         /// </summary>
34         /// <param name="text"></param>
35         /// <returns></returns>
36         public static string GetDetailVersion(string text)
37         {
38             //通过注册表获取用户IE版本号
39             RegistryKey mainKey = Registry.LocalMachine;
40             RegistryKey subKey = mainKey.OpenSubKey(text);
41 
42             var versionNumber = subKey?.GetValue("svcVersion")?.ToString() ?? string.Empty;
43             if ( string.IsNullOrEmpty(versionNumber))
44             {
45                 versionNumber = subKey?.GetValue("svcUpdateVersion")?.ToString() ?? string.Empty;
46                 if (string.IsNullOrEmpty(versionNumber))
47                 {
48                     versionNumber = subKey?.GetValue("Version")?.ToString() ?? string.Empty;
49                 }
50             }
51             return versionNumber;
52         }
53     }

 

作者:唐宋元明清2188