如何测试“Microsoft Windows 7 Home Premium”是否可用操作系统使用VBScript吗?

发布于 2024-08-19 09:28:07 字数 1002 浏览 4 评论 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,但是我仍然不明白为什么“标题”和我的字符串不相等平等的。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

预谋 2024-08-26 09:28:07

您确定您安装的是“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 
......

检查长度......

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

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

and try a different way

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

check the length as well...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文