Introducing Windows Management Instrumentation (WMI)
page 2 of 4
by Steven Swafford
Feedback
Average Rating: 
Views (Total / Last 10 Days): 34993/ 67

Interfacing with WMI instances

[ download code ]

I will discuss two radically different methods of interfacing with WMI instances both of which are fairly simple and straight forward. Basically it comes down to a personal choice and the requirements defined by the application that you are writing.

WMI Query Language (WQL) allows you to query WMI providers using a SQL-like query language, so if you are familiar with SQL then you will find WQL all to familiar. If you know the provider classes and the fields available, then you can get the info very easily.  For instance, if you wanted to get a list of logical drives from a system you would use the following query:

Select * from Win32_LogicalDisk

You can, however, refine the search by using where clauses and getting specific "fields" in the query. The following query gets the amount of free space, the size, and the name of all fixed disk drives:

Select FreeSpace, Size, Name from Win32_LogicalDisk where DriveType = 3

If you are not sure what provider classes and fields are available to you then this is where the WMI Administrative Tools will come in handy. Take the following steps:

  • Download and install the WMI Administrative Tools.
  • Once installed under the WMI Tools program group, click "WMI Object Browser".

The object browser will allow you to view the provider classes and associated field within a given class. Upon running the object browser you will be presented a screen as follows:

Figure 1
Figure 1

  • Click "OK".

Figure 2
Figure 2

  • Click OK. Then you will be presented a screen similar to the following:

Figure 3
Figure 3

As you can see in the above instance we are looking at the Win32_ComputerSystem provider class on the left hand side and the available fields on the right hand side of the above screen. In order to perform WQL queries in you class you will need to import the System.Management Namespace. The classes we will discuss are:


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-10-23 7:21:09 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search