1. 程式人生 > >C# 獲取系統當前IE版本號

C# 獲取系統當前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. 讀取IE的版本號

1     var versionNumber = subKey?.GetValue("
svcVersion").ToString(); 2 if (string.IsNullOrWhiteSpace(versionNumber)) 3 { 4 versionNumber = subKey?.GetValue("svcUpdateVersion").ToString(); 5 if (string.IsNullOrWhiteSpace(versionNumber)) 6 { 7 versionNumber = subKey?.GetValue("Version").ToString();
8 } 9 }

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.Contains(".")) 13 { 14 majorVersion = detailVersion.Substring(0, detailVersion.IndexOf(".", StringComparison.Ordinal)); 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 = subKey?.GetValue("svcVersion").ToString(); 39 if (string.IsNullOrWhiteSpace(versionNumber)) 40 { 41 versionNumber = subKey?.GetValue("svcUpdateVersion").ToString(); 42 if (string.IsNullOrWhiteSpace(versionNumber)) 43 { 44 versionNumber = subKey?.GetValue("Version").ToString(); 45 } 46 } 47 return versionNumber ?? string.Empty; 48 } 49 }