VBScript IF语句确定操作系统版本和ServicePack

时间:2012-04-11 01:24:32

标签: vbscript wmi

我正在为Office 2010和其他几个应用程序编写部署脚本,我们在测试中遇到的一个问题是一些计算机仍然有XP SP2,所以我想为此编写一个安全措施

我想出了这个

Set colOperatingSystem = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystem
ServicePack = objOperatingSystem.ServicePackMajorVersion
Next

IF not ServicePack = "3" Then

MsgBox "WARNING: prerequisite to installing Microsoft Office 2010 Professional you must first install service pack 3" & VbCrlf & "your current Service Pack Version is " & ServicePack

ELSE

'Do Nothing

END IF

我将它插入XP SP2机器并获得警告弹出On_WindowLoad,所以我很高兴,但是当我将它插入我的Windows 7机器时,它会抛出相同的消息,挖掘一下PowerShell,我意识到因为Windows 7将其ServicePackMajorVersion编号报告为“1”,因此它不符合条件,

希望有人可能知道如何编写IF /条件语句以绕过Windows 7 PC,我看了7601的内部版本号,但不确定如何嵌套这些

2 个答案:

答案 0 :(得分:6)

要测试您是否在Windows XP下运行,您必须检查Version WMI类的Win32_OperatingSystem属性是否以5.1

开头

检查此样本

strComputer = "."
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")        
Set colOperatingSystem = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystem
ServicePack = objOperatingSystem.ServicePackMajorVersion
Version = objOperatingSystem.Version

Next

IF Mid(Version,1,3)="5.1" And  not ServicePack = "3" Then

MsgBox "WARNING: prerequisite to installing Microsoft Office 2010 Professional you must first install service pack 3" & VbCrlf & "your current Service Pack Version is " & ServicePack

ELSE

'Do Nothing

END IF

答案 1 :(得分:0)

退房:http://www.tek-tips.com/viewthread.cfm?qid=1249039

首先查找操作系统版本然后如果XP查找SP 3,如果Win 7查找SP 1。