使用VBScript,如何列出所有具有方法的WMI类?
答案 0 :(得分:2)
运行SELECT schema query以获取命名空间中所有类的列表,然后检查每个类的Methods_.Count
:
strComputer = "."
strNamespace = "root\cimv2"
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\" & strNamespace)
Set colClasses = oWMI.ExecQuery("SELECT * FROM meta_class")
For Each oClass in colClasses
If oClass.Methods_.Count > 0 Then
WScript.Echo oClass.Path_.Class
End If
Next
您可能希望仅将结果限制为dynamic and static classes,就像WMI Code Creator一样。为此,请添加对相应类限定符的附加检查。
...
For Each oClass in colClasses
For Each oQualifier In oClass.Qualifiers_
strQualName = LCase(oQualifier.Name)
If strQualName = "dynamic" OR strQualName = "static" Then
If oClass.Methods_.Count > 0 Then
WScript.Echo oClass.Path_.Class
End If
End If
Next
Next
我还建议您阅读WMI Scripting Primer: Part 2文章。它详细解释了WMI概念和基础设施以及示例,并且可能已经为您未来的问题提供了答案。 :)