讀取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 }
1. 註冊表中,IE的位置:spa
計算機\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorercode
2. 經過註冊表讀取IE配置blog
1 RegistryKey mainKey = Registry.LocalMachine; 2 RegistryKey subKey = mainKey.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer");
3. 獲取主版本號(8/9/10 etc.)string
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 }