如何测试“Microsoft Windows 7 Home Premium”是否可用操作系统使用VBScript吗?
我的第一次尝试是查询 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,但是我仍然不明白为什么“标题”和我的字符串不相等平等的。
My first attempt is to query Win32_OperatingSystem for the caption, and test whether the caption "equals" the operating system I am testing for:
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
I suppose I can use InStr, however I still do not understand why the "Caption" and my string are not equal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定您安装的是“Microsoft Windows XP”而不是“Microsoft Windows XP Professional”吗?如果您使用“=”符号,那么您将无法捕获它,因为它期望匹配精确的字符串。如果你想要部分匹配,使用 instr() 会更好。否则,添加“专业”
您可以在找到标题后进行一些调试
,并尝试用不同的方式
检查长度......
Are you sure you have "Microsoft Windows XP" and not "Microsoft Windows XP Professional" ?. If you use "=" sign, then you will not catch it because it expects to match exact string. Use instr() would be better if you want partial match. Otherwise, add in "Professional"
You can put in some debugging after caption is found
and try a different way
check the length as well...