0

我的第一次尝试是查询 Win32_OperatingSystem 的标题,并测试标题是否“等于”我正在测试的操作系统:

Dim objWMIService, strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")


msgbox getOperatingSystemCaption()
msgbox meetsOperatingSystemRequirement()



Function getOperatingSystemCaption()

     Dim strCaption, colOperatingSystems, objOperatingSystem

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

     For Each objOperatingSystem in colOperatingSystems
        strCaption = objOperatingSystem.Caption
        Exit For 
     Next

    getOperatingSystemCaption = strCaption

End Function





Function meetsOperatingSystemRequirement()

    meetsOperatingSystemRequirement = False 

    If getOperatingSystemCaption() = "Microsoft Windows 7 Home Premium" Then 

       meetsOperatingSystemRequirement = True

    End If 


End Function

我想我可以使用 InStr,但是我仍然不明白为什么“Caption”和我的字符串不相等。

4

1 回答 1

2

您确定您拥有的是“Microsoft Windows XP”而不是“Microsoft Windows XP Professional”吗?如果您使用“=”符号,那么您将无法捕捉到它,因为它希望匹配精确的字符串。如果您想要部分匹配,使用 instr() 会更好。否则,添加“专业”

找到标题后可以进行一些调试

....
        msgbox strCaption & " " & len(strCaption)
        getOperatingSystemCaption = strCaption
....

并尝试不同的方式

.....
    myCaption = getOperatingSystemCaption()
     msgbox myCaption & " " & len(myCaption)
    If myCaption = "Microsoft Windows XP Premium Home" Then 
......

还要检查长度...

于 2010-01-23T00:38:35.057 回答