WMI SDK Sample - QueryParser

Windows Management Instrumentation SDK Sample

QueryParser

This sample demonstrates how to use the WMI Query Language (WQL) parser COM object. WMI providers that choose to implement query support to optimize the retrieval of their instance data can use this object to parse the various components of the WQL query submitted by a client application. Based upon the analysis of the query, the provider can then decide if it will handle the query itself or let WMI itself do so.

This application is a console application meant to be run at the command line. In the interests of being an example and educational, the code is designed to be easy to follow but does not necessarily always do the error checking required for a product quality application.

Using the QueryParser Sample

The QueryParser sample can be built from the command line using NMAKE, or it can be built using Microsoft Visual C++.

From the command line in the sample installation directory, type the following:

NMAKE /f “Makefile”

From Microsoft Visual C++:

1. Select File + Open Workspace

2. Select the QueryParser.DSP file

Once built the QueryParser sample application can be run from the command line in the sample installation directory:

QueryParser

The valid syntax for QueryParser:

QueryParser

With no parameters, the usage message is printed out which will have several sample queries.

General Notes

Things to remember when you're building your own WMI client application:

1. WMI interfaces are defined in wmiutils.h found in the wmi\include directory.

2. WMI interface CLSIDs are defined in wbemuuid.lib. If you get unresolved externals in interfaces and CLSIDs, this is what is missing.

3. You'll need to link with oleaut32.lib and ole32.lib to get the needed COM support.

4. If you're using the makefiles, don't forget to set the Visual C++ environment variables. This is done by running VCVARS32.BAT.