28 December 2011

WBEMTEST - A simple tool to access WMI classes

Windows Management Instrumentation (WMI) is the repository of windows information. Basically WMI contains a whole bunch of classes where each class holds complete information about some part of windows. For example there is a class called Win32_Printer which represents a printer installed in the system. Similarly there is a Win32_Product which represents a product installed in the system. You can complete information of all WMI classes here.

Whenver you decide to use WMI for accessing any piece of information, the first thing is to know which class contains the information and what are all the properties and methods present in that class. Initially, I always used to visit msdn to search for the right class and its components. This usually is quite time consuming. That time I cam across a handy tool that comes along with windows operating system itself - wbemtest.exe. This tool is quite handy - you can quickly access a class to know what and all properties it contains. Also, you can access existing istances of these classes. For example, there exist as many istannces of Win32_Processor class as the number of processors present in the system. If you are interested in knowing any information about a perticular processor, you can open corresponding instance. Here is how you can use wbemtest.exe to access existing instances of Win32_Processor class.

1. Run "wbemtest.exe" either from command prompt or directly from \System32\wbem folder. This will open the window shown in below figure.



2. Then click "Connect" button. This will open a window (Figure B) where you have to give the namespace which contains your desired class. A namespace is just like your C# namespace, which contains many classes. You can also think of namespace as a category like CimV2, SecurityCenter etc. Find more info on these namespaces here.



3. I am intersted in Win32_Processor class which is in cimv2 namespace. So, I will enter cimv2 and click connect. This will load cimv2 and all the buttons in first figure will be enabled. Click "Enum Instances" button which will ask you to enter the class name. It looks like below.



4. Click Ok. This will open another window listing all the instances of Win32_Processor. In my computer, there is only one processor in my system, so i get only one entry.



5. Double click on the entry. This will open the details of the processor which looks like below image. You can see that the window lists all Win32_Processor class properties with values loaded into them. So, you can get all information like, processor architecture, name, address width, data width etc.


Isn't this a nice tool? One drawback of this tool is that you need to know which class you want to access which means you cannot loop through all WMI classes. But, this tool is very handy as it is at your fingertip. I hope you too will find this useful.

2 comments: