如何使用Vbscript显示WMI类属性的描述?

时间:2014-03-25 05:03:52

标签: vbscript wmi

我一直在寻找一种以编程方式输出WMI类属性描述的方法,但是无法找到如何访问修改后的限定符。

我看过this question on how to use VBScript to display WMI class descriptions,使用以下代码段:

    Const wbemFlagUseAmendedQualifiers = &H20000

    Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set oClass = oWMI.Get("Win32_OperatingSystem", wbemFlagUseAmendedQualifiers)

    WScript.Echo oClass.Qualifiers_("Description").Value

以下图片是我要提取的内容,如WMI Code Creator中所示:

enter image description here

是否有这样的方法可以显示描述?

    Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set oProp = oWMI.Get("Win32_OperatingSystem.BootDevice", wbemFlagUseAmendedQualifiers)

    WScript.Echo oProp.Qualifiers_("Description").Value

1 个答案:

答案 0 :(得分:3)

你快到了。拿第一个例子,将Properties_("BootDevice")插入最后一行:

Const wbemFlagUseAmendedQualifiers = &H20000

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oClass = oWMI.Get("Win32_OperatingSystem", wbemFlagUseAmendedQualifiers)

WScript.Echo oClass.Properties_("BootDevice").Qualifiers_("Description").Value

或者如果您需要遍历所有类属性:

...
On Error Resume Next
For Each oProp in oClass.Properties_
  WScript.Echo oProp.Name & ": " & oProp.Qualifiers_("Description").Value
Next