Abbey的小匣子

记载我编程之路的点点滴滴,分享我搜集到的零零碎碎

<2010年8月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

留言簿(4)

随笔档案

文章分类

文章档案

相册

相关链接

搜索

最新评论

阅读排行榜

评论排行榜

利用WMI判断IE版本、判断Windows版本


一、判断IE版本

在网上找了很多判断IE版本的办法,大多是通过读取注册表中IE的Build值实现的。我在搜索WMI时发现了MicrosoftIE这个命名空间,仔细再看,又找到了一个类MicrosoftIE_Summary。经过一番试探,找到了其中的一个属性Build,即与注册表中一致的IE内部版本号,格式为

major version build number.sub-build number

随即,我又在http://support.microsoft.com/kb/164539/zh-cn上找到了各版IE对应的Build列表

版本                产品
-----------------------------------------------------------------
4.40.308         Internet Explorer 1.0 (Plus! for Windows 95)
4.40.520         Internet Explorer 2.0
4.70.1155        Internet Explorer 3.0
4.70.1158        Internet Explorer 3.0 (Windows 95 OSR2)
4.70.1215        Internet Explorer 3.01
4.70.1300        Internet Explorer 3.02 和 3.02a
4.71.544         Internet Explorer 4.0 Platform Preview 1.0 (PP1)
4.71.1008.3      Internet Explorer 4.0 Platform Preview 2.0 (PP2)
4.71.1712.6      Internet Explorer 4.0
4.72.2106.8      Internet Explorer 4.01
4.72.3110.8      Internet Explorer 4.01 Service Pack 1 (Windows 98)
4.72.3612.1713   Internet Explorer 4.01 Service Pack 2
5.00.0518.10     Internet Explorer 5 Developer Preview (Beta 1)
5.00.0910.1309   Internet Explorer 5 Beta (Beta 2)
5.00.2014.0216   Internet Explorer 5
5.00.2314.1003   Internet Explorer 5 (Office 2000)
5.00.2614.3500   Internet Explorer 5 (Windows 98 Second Edition)
5.00.2516.1900   Internet Explorer 5.01 (Windows 2000 Beta 3, build 5.00.2031)
5.00.2919.800    Internet Explorer 5.01 (Windows 2000 RC1, build 5.00.2072)
5.00.2919.3800   Internet Explorer 5.01 (Windows 2000 RC2, build 5.00.2128)
5.00.2919.6307   Internet Explorer 5.01 (Office 2000 SR-1)
5.00.2920.0000   Internet Explorer 5.01 (Windows 2000, build 5.00.2195)
5.00.3103.1000   Internet Explorer 5.01 SP1 (Windows 2000 SP1)
5.00.3105.0106   Internet Explorer 5.01 SP1(Windows 95/98 和 Windows NT 4.0)
5.00.3314.2101   Internet Explorer 5.01 SP2(Windows 95/98 和 Windows NT 4.0)
5.00.3315.1000   Internet Explorer 5.01 SP2 (Windows 2000 SP2)
5.00.3502.1000   Internet Explorer 5.01 SP3(仅 Windows 2000 SP3)
5.00.3700.1000   Internet Explorer 5.01 SP4(仅 Windows 2000 SP4)
5.50.3825.1300   Internet Explorer 5.5 Developer Preview (Beta)
5.50.4030.2400   Internet Explorer 5.5 和 Internet 工具 (Beta)
5.50.4134.0100   Internet Explorer 5.5 for Windows Me (4.90.3000)
5.50.4134.0600   Internet Explorer 5.5
5.50.4308.2900   Internet Explorer 5.5 Advanced Security Privacy Beta
5.50.4522.1800   Internet Explorer 5.5 Service Pack 1
5.50.4807.2300   Internet Explorer 5.5 Service Pack 2
6.00.2462.0000   Internet Explorer 6 Public Preview (Beta)
6.00.2479.0006   Internet Explorer 6 Public Preview (Beta) Refresh
6.00.2600.0000   Internet Explorer 6 (Windows XP)
6.00.2800.1106   Internet Explorer 6 Service Pack 1 (Windows XP SP1)
6.00.2900.2180   Internet Explorer 6 for Windows XP SP2
6.00.3663.0000   Internet Explorer 6 for Windows Server 2003 RC1
6.00.3718.0000   Internet Explorer 6 for Windows Server 2003 RC2
6.00.3790.0000   Internet Explorer 6 for Windows Server 2003(已发行)
6.00.3790.1830   Internet Explorer 6 for Windows Server 2003 SP1 和 Internet Explorer 6 for Windows XP x64
7.00.5730.1100   Internet Explorer 7 for Windows XP 和 Internet Explorer 7 for Windows Server 2003
7.00.6000.16386  Internet Explorer 7 for Windows Vista

剩下的代码便很简单了,比如这样的:

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2\Applications\MicrosoftIE",
    @"SELECT * FROM MicrosoftIE_Summary"
))
{
     
string ieBuild = string
.Empty;

     
foreach (ManagementObject queryObj in
 searcher.Get())
        ieBuild 
= queryObj["Build"
].ToString();

     
if ((new Version(ieBuild)) < new Version("52014.0216"
))
        
return
;
   }


二、判断Windows版本

与上述方法类似,只是换了个命名空间和相应的类,这回是root\CIMV2下的Win32_OperatingSystem。这个类有CaptionBuild等属性,我更喜欢用Caption,免去了比较数字形式的版本号之累,简单的字符串匹配就可以完成判断:

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2",
   
"SELECT * FROM Win32_OperatingSystem"))
{
     
string osCaption = string.Empty;

     
foreach (ManagementObject queryObj in searcher.Get())
       osCaption 
= queryObj["Caption"].ToString();

    
if (osCaption.IndexOf(@"Windows XP"< 0)
       
return;
   }


posted on 2007-06-21 23:40 Abbey的小匣子 阅读(885) 评论(7)  编辑 收藏

评论

标题  
姓名  
主页
验证码 *
内容   
  登录  使用高级评论  Top
[使用Ctrl+Enter键可以直接提交]