Windows Management Instrumentation SDK Sample


PathParser

This sample demonstrates how to use the WMI object path parser COM object. WMI object paths are the strings WMI uses to uniquely identify WMI class and instance objects.  Many times it is necessary for WMI clients and providers to parse this string to obtain the various parts of the object path it contains.  An example of an object path is the following:

 

\\MyServer\root\cimv2:Win32_Printer.DeviceID="MyLaserPrinter"

 

In this example which points to a printer installed on a computer, the server where this WMI object is located is MyServer.  The class is called Win32_Printer and it is stored in the root/cimv2 namespace.  Finally, the specific printer is called MyLaserPrinter which is the value set in the single key property for the Win32_Printer class, DeviceID.  At any given time, it may be useful to retrieve some or all of these values from a given WMI object path.

 

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 PathParser Sample

 

The PathParser 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 PathParser.DSP file

 

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

 

PathParser

 

The valid syntax for PathParser:

 

PathParser

 

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

 

 

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.