WMI Programming with Visual Basic.NET: What is the WQL? - Working with WQL Schema queries
(Page 4 of 4 )
As explained in the previous section, schema queries are used to retrieve class definitions. The following simple example lists all of the classes in the WMI environment.
DimsearcherAsNewManagementObjectSearcher("SELECT * FROM meta_class")
DimwmiClassAsManagementClass
ForEachwmiClassInsearcher.Get()
Me.lstMembers.Items.Add(wmiClass("__CLASS").ToString())
Next
Interesting! You will be able to find approximately 800+ classes. So, you can imagine how much information you can gather from WMI. You can observe that the SELECT statement is being used with “meta_class” which works in a way similar to the concept of reflection in .NET. You can obtain the above code from the “form3.vb” file in the zip included for download.
Can we get all of the namespaces in the same way as above? Why not? I hope you would be glad to work with that one too. The following shows you how to do it (and can be found at “form4.vb”):
DimnsClassAsNewManagementClass( _
NewManagementScope("root"), _
NewManagementPath("__namespace"), _
Nothing)
DimnsAsManagementObject
ForEachnsInnsClass.GetInstances()
Me.lstMembers.Items.Add(ns("Name").ToString())
Next
Can we get all of the sub-namespaces of a particular namespace? Why not? In the above example, replace “root” with your own known namespace such as “root\cimv2” or “root\Microsoft” or whatever is appropriate. The program automatically retrieves all of the sub-namespaces available within the namespace specified (and can be found at “form5.vb”).
And finally, the following example gives you the list of all the classes available in a particular namespace (and can be found at “form6.vb”).
DimsearcherAsNewManagementObjectSearcher( _
NewManagementScope("root\" &Me.lstNamespaces.Text), _
NewWqlObjectQuery("select * from meta_class"), _
Nothing)
DimwmiClassAsManagementClass
ForEachwmiClassInsearcher.Get()
Me.lstClasses.Items.Add(wmiClass("__CLASS").ToString())
NextwmiClass
In the above program, you can replace “me.lstnamespaces.text” with any namespace you want. The above program actually tries to list all the classes of the namespace selected in the ‘lstNamespaces’ control.
Using all of the examples in this section, together with some investigation of System.Management classes, you can also design WMI object explorer (both for local and remote) completely by yourself. The object explorer could either be windows based or Web based (following the strategy of WBEM). But, it needs some indepth study of certain classes within the same namespace. I leave it to the readers to further investigate and research the System.Management namespace.
For a complete list of all namespaces and classes, I suggest you refer to MSDN or WMI SDK. The WMI SDK documentation contains all the namespaces and classes, beautifully organized based on the categories. All of the members of each and every class present in WMI are thoroughly discussed within the WMI SDK.
In my upcoming articles, I would like to cover as many examples as possible to get several types of information from WMI. We shall also implement both the Windows and Web styles of interfacing through WMI. The topic of “Event Queries” (discussed above) has to be dealt with indepth. I will present a wonderful example of event consuming through windows service using WMI as part of this series.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |