WMI Programming with Visual Basic.NET: What is the WQL? - Types of WQL queries
(Page 3 of 4 )
The previous sections just demonstrated some simple examples of WQL. Actually WQL has its own classification of queries. They are as follows:
- Data Queries
- Event Queries
- Schema Queries
Every WMI class instance represents a physically existing resource residing at your computer or on the network or at any location. Any physical resource (or instance) would definitely fall into a category of a particular WMI class, where we can query all those instances through WQL.
Data queries are used to retrieve WMI class instances and data associations. They are the most commonly used type of query in WMI scripts and applications. All the examples in the previous sections are of the Data query type (as we are trying to retrieve the instances of WMI class ‘Win32_LogicalDisk’).
Every programmer knows that the entire Windows operating system is event-driven. Anything you operate with Windows OS is an event. Examples of events include logging in, logging out, printing a page, installing software, opening an application, connecting to a network, and so forth. Now, say I wanted to have some script executed when someone logs in. That means my script should register to the “login” (for example) event, and continuously listen for that event to occur. When the event occurs, my script gets executed.
These kinds of scripts (listening for events of WMI) are called consumers. Consumers use event queries to register and receive notification of events. Event providers use event queries to register one or more events. In general, the queries used for trapping event notifications are called “event queries” (which will be discussed in my upcoming articles).
How do you list all of the namespaces available? How many sub-namespaces does each of the main namespaces contain? What are the classes owned by a particular namespace? How do you get this type of information (programmatically)? For all of the previous questions, “schema queries” is the answer. Schema queries are used to retrieve class definitions (rather than class instances) and schema associations. Schema queries use the SELECT statement with syntax similar to that for data queries. The difference is the use of a special class called “meta_class”, which identifies the query as a schema query. Schema queries only support "*" in the SELECT statement. To narrow the scope of the definitions returned, a provider can add a WHERE clause that specifies a particular class.
The next section will give you some introduction to schema queries and how to use them efficiently to solve our needs.
Next: Working with WQL Schema queries >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee