How to list all WMI classes having methods using VBScript?

。_饼干妹妹 提交于 2020-12-06 04:23:25

问题


Using VBScript, how can I list all WMI classes that have methods?


回答1:


Run a SELECT schema query to get a list of all classes in a namespace, and then check each class's 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

You may want to limit the results to dynamic and static classes only, like WMI Code Creator does. To do this, add an additional check for the corresponding class qualifiers.

...
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

I also suggest that you read the WMI Scripting Primer: Part 2 article. It explains the WMI concepts and infrastructure in detail and with examples, and may already hold answers to your future questions. :)



来源:https://stackoverflow.com/questions/3993852/how-to-list-all-wmi-classes-having-methods-using-vbscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!