Wednesday, June 23, 2010

Testing WQL based WMI queries (wbemtest)

Windows Management Instrumentation (WMI) makes life easier for developers to get those information which have been very difficult to get earlier. Not only we can get these information, we can also make them available to any System Management tools like Microsoft System Center. They can be used to provide centralized management and administration of all applications. The administrators are no more required to look at various logs created everywhere on various standalone and network machines.

The real issue is to test our WMI queries. Windows provides a tool to provide just for this. This tool is called WBEMTEST. You can start this by typing WBEMTEST on run box in start menu.



As soon as you press OK, following form is shown on the screen:



Since WMI objects are defined in various namespaces, you would need to connect to the required namespace before querying any specified WMI object. Select "Connect" and enter namespace information on the following form:



As you can see, we have selected CIMV2 which have required WMI objects we would be accessing shortly. When you select namespace, it is selected on the main form as follows:



Since we are connected to the required namespace, we can write queries for any object in this namespace. As you might know, the names of WMI objects traditionally start from "win32_". Here we are accessing information from WIN32_COMPUTERSYSTEM object.



We have written following WQL query:

Select * from win32_ComputerSystem

If you provide a valid WMI object then the result gets loaded. Otherwise, it results in weird exception messages.



You can view the properties of the object by double clicking the query result item. In our case, the properties are as follows:



In this way, we can select the properties of any WMI object.

No comments: