This article mainly introduced the WQL language introduction and the WQL Test tool Wbemtest.exe Use method detailed introduction, WQL refers to the Windows Management Specification query language, needs the friend can refer to the next
WQL is the query language in WMI, the full name of the WQL is WMI query Language, referred to as WQL, translated into Chinese seems to be the Windows Management Specification query language. A friend who is familiar with the SQL language will feel that it is very similar to SQL.
WQL is actually very simple, it has the following characteristics:
1, each WQL statement must start with select;
2, select and you need to query the name of the property (I just referred to SQL as a field name), or like SQL, with * to return all property values;
3, from the keyword;
4, the name of the class you want to query;
5, in addition, if you want accurate query results can also be added where conditional clauses. For example, if a class has an ENABLE property, you can add a where enable=true to the query.
The following are the correct WQL statements:
Copy CodeThe code is as follows:
Select * from Win32_LogicalDisk where drivetype=3 "" Query all hard disk partitions
SELECT * from Win32_Share ' Query all shared directories
SELECT * from Win32_NetworkAdapterConfiguration WHERE dhcpenabled=true
SELECT Description from Win32_account WHERE name= ' Administrator '
SELECT Freespace,deviceid from Win32_LogicalDisk
In WinXP and Win2003, there is a self-contained WQL test tool called Wbemtest.exe, which can be used to see which classes and classes have properties, using the following method:
First, run Wbemtest.exe, such as:
A window with the Windows Management Instrumentation Tester appears after you click OK, such as:
Click "Connect" will appear a dialog box, we can choose to connect to the local host or remote host, such as:
If it is a native test and is logged in as an administrator, you can not fill in the user name and password, if it is linked to the remote host will need to fill in the remote host user name and password (recommended to use the remote host Administrator login), click "Connect" will return to the main interface. Note that you can only view and query after logging in.
Click the "Query" button, enter the WQL statement we want to query, such as "SELECT * from Win32_LogicalDisk", which is the WQL statement of the query system logical drive,
This is the error that we would probably get a number for "0x80041010", described as "Invalid category", such as:
This error occurs because the default namespace is "Root/default" at the beginning, and we need to change the namespace. Then click the "Connect" button, change the default "Root/default" to "root/cimv2", then click the "Connect" button, such as:
Once the login is successful, we can see what classes the system has and can also execute WQL queries.
You can query the properties of a class by tapping the Enum category button and entering the class name you want to find in the popup dialog box. such as (note: I did not fill in the superclass name, and select the "Recursive" radio button, so that is recursive enumeration of all classes in the system):
Query results such as:
These can all be useful things oh, if you are careful, you will find in this list all the classes that I used to design in the WQL statement, such as Win32_LogicalDisk, Win32_Share, and so on. It is important to note that some have parentheses, and these are methods.
Here are the results of some queries:
We can also double-click on one of the data to view properties, such as:
If we are not accustomed to this way of viewing, we can also click on the "Show MOF" button in the above window, which is the result of my clicking on the "Show MOF" button:
From the above figure, you can see what the properties and corresponding property values of this class are.
Today's content seems to have nothing to do with. NET, but only understanding and familiarity with WQL will enable us to write. NET code quickly and smoothly.
WMI Tester (Wbemtest.exe) Walkthrough
Now that you have some knowledge of the tools available for browsing and viewing the CIM, let's use the WMI Tester (Wbemtest.exe) to examine the Win32_Process class definition and modify the manifest 2 to retrieve some properties from the process that is running on your local computer.
Open a command prompt, type C:\>wbemtest.exe, and press Enter to start the WMI Tester tool. Note that most of the buttons are disabled on the main WMI Tester window, which means that you are not connected to WMI at this time.
Click Connect to connect to the WMI service on a local or remote computer. Displays the connection dialog box, which provides a text input area labeled Namespace , which is the default value of root\default. To change the value of the Namespace area to root\cimv2, click the Connect button in the Connection dialog box to return to the main WMI tester window.
The namespace identifier in the upper-left corner of the main window should be displayed as root\cimv2. Note that all the buttons are now enabled, which means that in the current credential environment, you have successfully connected to WMI on the local host. Click Enum Classes? opens the Superclass Information dialog box.
In the Superclass Information dialog box, do not fill in the Enter superclass name area, click the Recursive option, and click OK to enumerate all the CIS defined in the root\cimv2 namespace Class M.
At this point, you might be viewing a Query Results dialog box that lists the hundreds of class definitions. The number of classes depends primarily on the version of Windows that you are running. For example, if you use Windows 2000, you should see about 600 class definitions. If you are running Windows XP, you should see about 900 class definitions.
Notice that the class listed at the top of the Query Results dialog box starts with two underscores. These are system classes. The system class is a predefined CIM class that supports internal WMI configuration and operations, such as provider registration, namespace security, and event notification. Now, ignoring the system class, scroll down the Query Results dialog box until you see a class that starts with cim_.
Classes with names beginning with cim_ are the core and common base classes maintained by the DMTF. Continue scrolling down until you reach the class that starts with Win32_.
The class whose name begins with Win32_ is the Microsoft extension class, which represents Windows-specific managed resources. If this is the first time you have checked the root\cimv2 namespace, you may want to familiarize yourself with the complete set of classes in the root\cimv2 namespace, especially classes with win32_ prefixes.
Scroll down the Query Results dialog box until you reach the Win32_Process class, and double-click the class name to open the Object Editor for the Win32_Process dialog box.
The Object Editor dialog box displays details (properties and methods) of the definition and implementation of the selected class. Recall what we discussed earlier-the class definition is the blueprint for WMI's manageable resources.
Select The Hide System Properties check box to hide the systems property. The remaining Win32_Process property represents information that you can retrieve from a process that is running on a local or remote computer.
To complete your WMI scripting exercise, try to retrieve the Name,Handle , and ProcessID properties. Using one of the previous three listings as a template, try running the script before you proceed to step 7th.
note to run the script on the local computer, set the value of the StrComputer variable to "." (a single point within the quotation marks).
After you run the newly created Getprocesses.vbs script, you can use the Wimi tester to verify the results of the script. In the object Editor of the Win32_Process dialog box, click Instances. The resulting Query Results dialog box lists the instances of the process that are running on the computer. Double-click a specified process instance to view the details of that instance.
Example
StrComputer = "." ' Dot (.) equals local computer in WMI
Set wbemservices = Getobject ("winmgmts:\\" & StrComputer)
Set wbemObjectSet = wbemservices.instancesof ("Win32_Process")
For each wbemobject in wbemObjectSet
WScript.Echo "Name:" & Wbemobject.name & VbCrLf & _
"Handle:" & Wbemobject.handle & VbCrLf & _
"Process ID:" & Wbemobject.processidnext
The WQL language introduction and the WQL Test tool Wbemtest.exe use method detailed introduction