本文介绍了从 WMI ExecQuery 获取第一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的 vbscript 来检索 Windows 版本:
I have a simple vbscript for retrieving the Windows version:
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colVersions = objWMI.ExecQuery("Select * from Win32_OperatingSystem")
For Each objVer in colVersions
ver = objVer.Version
Next
是否可以获取第一条记录,或者我是否必须遍历集合中的所有记录.我见过的所有例子都是 For Each
结构.我在尝试时收到 Expected end of statement 错误:
Is is possible to get the first record or do I have to loop over all records in the collection. All examples I've seen are with For Each
construction. I receive Expected end of statement error when I try:
ver = colVersions[0].Version
看起来 ExecQuery
的返回值不是一个正确的集合.
It looks like the return value of ExecQuery
is not a proper collection.
推荐答案
For Each objVer in colVersions
ver = objVer.Version
exit for
Next
这篇关于从 WMI ExecQuery 获取第一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!