2014-03-25 41 views
2

我一直在寻找一种以编程方式输出WMI类属性的说明的方法,但无法找到如何访问修改的限定符。如何使用Vbscript显示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代码创建者显示的内容:

enter image description here

有没有一种方法像这样可以显示说明?

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

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

回答

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 
+0

辉煌。现在我明白这一点非常有意义。优秀,简洁的答案。谢谢! – treehead