本文實例為大家分享了C#獲取系統當前IE版本號的具體代碼,供大家參考,具體內容如下
1. 注冊表中,IE的位置:
計算機\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer
2. 通過注冊表讀取IE配置
1
2
|
RegistryKey mainKey = Registry.LocalMachine; RegistryKey subKey = mainKey.OpenSubKey( @"SOFTWARE\Microsoft\Internet Explorer" ); |
3. 讀取IE的版本號
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/// <summary> /// 獲取IE詳細版本號 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string GetDetailVersion( string text) { //通過WebBrowser方案獲取版本號 //int mainVer = (new WebBrowser()).Version.Major; //通過注冊表獲取用戶IE版本號 RegistryKey mainKey = Registry.LocalMachine; RegistryKey subKey = mainKey.OpenSubKey(text); var versionNumber = subKey?.GetValue( "svcVersion" )?.ToString() ?? string .Empty; if ( string .IsNullOrEmpty(versionNumber)) { versionNumber = subKey?.GetValue( "svcUpdateVersion" )?.ToString() ?? string .Empty; if ( string .IsNullOrEmpty(versionNumber)) { versionNumber = subKey?.GetValue( "Version" )?.ToString() ?? string .Empty; } } return versionNumber; } |
4. 獲取主版本號(8/9/10 etc.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/// <summary> /// IE瀏覽器版本號幫助類 /// </summary> public static class IEVersionHelper { /// <summary> /// 獲取IE主版本號 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string GetMajorVersion( string text) { var majorVersion = string .Empty; var detailVersion = GetDetailVersion(text); if (! string .IsNullOrWhiteSpace(detailVersion)) { if (detailVersion.IndexOf( "." , StringComparison.Ordinal) is int connectedCharFirstIndex && connectedCharFirstIndex > -1) { majorVersion = detailVersion.Substring(0, connectedCharFirstIndex); } else { majorVersion = detailVersion; } } return majorVersion; } /// <summary> /// 獲取IE詳細版本號 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string GetDetailVersion( string text) { //通過注冊表獲取用戶IE版本號 RegistryKey mainKey = Registry.LocalMachine; RegistryKey subKey = mainKey.OpenSubKey(text); var versionNumber = subKey?.GetValue( "svcVersion" )?.ToString() ?? string .Empty; if ( string .IsNullOrEmpty(versionNumber)) { versionNumber = subKey?.GetValue( "svcUpdateVersion" )?.ToString() ?? string .Empty; if ( string .IsNullOrEmpty(versionNumber)) { versionNumber = subKey?.GetValue( "Version" )?.ToString() ?? string .Empty; } } return versionNumber; } } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/kybs0/p/9994410.html