2014-03-25 42 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