我正在为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
Run Code Online (Sandbox Code Playgroud)
我将它插入XP SP2机器并获得警告弹出On_WindowLoad,所以我很高兴,但是当我将它插入我的Windows 7机器时,它会抛出相同的消息,挖掘一下powershell我意识到自从Windows 7报告它的ServicePackMajorVersion数字为"1",因此它不符合条件,
希望有人可能知道如何写一个IF /条件声明来绕过Windows 7 PC,我看了7601的内部版本号,但不知道如何嵌套这些
要测试您是否在Windows XP下运行,您必须检查WMI类的Version属性是否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
Run Code Online (Sandbox Code Playgroud)