2012-04-11 79 views
0

我正在为Office 2010和其他几个应用程序编写部署脚本,我们在测试中遇到的一个问题是某些计算机仍然具有XP SP2,所以我想要为此编写一个安全措施。VBScript IF语句确定操作系统版本和ServicePack

我想出了这个

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,但不知道如何嵌套这些

回答

6

要测试,如果你在Windows XP下运行,就必须检查如果Win32_OperatingSystem WMI类的Version财产开始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

在我的完美主义者真的婉ts更改代码以测试Service Pack *小于3 *,但我意识到这可能是静态的,因为不会有SP4。 – 2012-04-11 05:19:48