0

我正在为 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,但不确定如何嵌套这些

4

2 回答 2

6

要测试您是否在 Windows XP 下运行,您必须检查WMI 类的Version属性是否以Win32_OperatingSystem5.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
于 2012-04-11T02:14:46.107 回答
0

查看:http ://www.tek-tips.com/viewthread.cfm?qid=1249039

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

于 2012-04-11T01:30:30.083 回答