欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-01-11 16:51:52
1. 注册表中,IE的位置: 计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer 2. 通过注册表读取IE配置 3. 读取IE的版本号 4. 获取主版本号(8/9/10 etc.) ......

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. 读取ie的版本号

 1     var versionnumber = string.empty;
 2     if (subkey?.getvalue("svcversion") is string svcversion)
 3     {
 4         versionnumber = svcversion;
 5         if (string.isnullorwhitespace(versionnumber) && subkey.getvalue("svcupdateversion") is string svcupdateversion)
 6         {
 7             versionnumber = svcupdateversion;
 8             if (string.isnullorwhitespace(versionnumber) && subkey.getvalue("version") is string version)
 9             {
10                 versionnumber = version;
11             }
12         }
13     }

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

 1     /// <summary>
 2     /// 获取ie主版本号
 3     /// </summary>
 4     /// <returns></returns>
 5     public static string getmajorversion()
 6     {
 7         var majorversion = string.empty;
 8 
 9         var detailversion = getdetailversion();
10         if (!string.isnullorwhitespace(detailversion))
11         {
12             if (detailversion.indexof(".", stringcomparison.ordinal) is int connectedcharfirstindex && connectedcharfirstindex > -1)
13             {
14                 majorversion = detailversion.substring(0, connectedcharfirstindex);
15             }
16             else
17             {
18                 majorversion = detailversion;
19             }
20         }
21 
22         return majorversion;
23     }
24 
25     /// <summary>
26     /// 获取ie详细版本号
27     /// </summary>
28     /// <returns></returns>
29     public static string getdetailversion()
30     {
31         //通过webbrowser方案获取版本号
32         //int mainver = (new webbrowser()).version.major;
33 
34         //通过注册表获取用户ie版本号
35         registrykey mainkey = registry.localmachine;
36         registrykey subkey = mainkey.opensubkey(@"software\microsoft\internet explorer");
37 
38         var versionnumber = string.empty;
39         if (subkey?.getvalue("svcversion") is string svcversion)
40         {
41             versionnumber = svcversion;
42             if (string.isnullorwhitespace(versionnumber) && subkey.getvalue("svcupdateversion") is string svcupdateversion)
43             {
44                 versionnumber = svcupdateversion;
45                 if (string.isnullorwhitespace(versionnumber) && subkey.getvalue("version") is string version)
46                 {
47                     versionnumber = version;
48                 }
49             }
50         }
51         return versionnumber;
52     }