WMI (Windows Management Instrumentation) Class Properties Inspector

More
3 years 8 months ago - 1 year 9 months ago #338 by John Fauss
John Fauss created the code: WMI (Windows Management Instrumentation) Class Properties Inspector
WMI Class Properties Inspector is a single-window application which illustrates how to obtain the properties of any Windows Management Instrumentation class that supports enumeration (the listing of class instances). WMI is a means for interrogating the features and capabilities of the hardware of a computer that runs the Windows operating system. For example, using WMI, you can obtain the manufacturer's serial number of a hard drive, see BIOS attributes, determine what Plug-and-Play (PNP) devices are connected, view network adapter settings, see what services are running, and much, much more. You can select from hundreds of WMI classes organized into approximately thirty categories. Although WMI supports (when appropriate rights are in place) the examination of remote systems, the sample application is limited to inspection of the local computer only.

The application was developed in PB 2017. It interfaces with WMI using COM+ via PB OLEObject objects. No Windows API functions are used. It has been tested on Windows 10 and Windows 7 as 32-bit and 64-bit applications.

The WMI class instances are obtained by issuing a WQL (SQL for WMI) query, a subset of ANSI SQL that is supported by WMI. Although the application only issues generic queries (such as "Select * from classname", for example), you will be able on your own to add a Where clause containing multiple conditions or otherwise tailor the query by adapting the code as your needs dictate. A URL for documentation on WQL is included in the comments in the function that obtains the WMI class instances. The code has been generously commented throughout the application.

Not every WMI class supports the enumeration of class instances. Those that do not are clearly identified. Although WMI returns information for the majority of classes quickly (less than one second), some take longer and a few can take a very long time (up to thirty minutes or more) to return. The class selection drop-down DataWindow provides a rough estimate of the anticipated response time (Fast, OK, Slow, or Very Slow) to give you an idea of what to expect. A tooltip over the response time keyword quantifies the expected response time. If a query returns more than 250 (configurable via instance variable) class instances, you are given the option whether you wish to proceed or not.

The class property name/value pairs for up to 10 class instances (also configurable) at a time are presented in a report DataWindow. Navigation buttons are provided and you may request the display of any single returned class instance.

<<<< Edit January 23, 2023 >>>>

In response to a question in the Q&A forum, I've created a second, more compact sample application and attached it here. The sample application originally posted here is essentially a general-purpose, WMI class property/value "inspector" that lets you see the information that is returned by nearly all of the Win32 computer system hardware classes. While this can be useful, I've realized that the effort needed to extract and re-package the "guts"... the logic that executes a WQL query and parses the property name/value pairs into a useful format, was substantial. I needed to make the functionality easier to adapt and integrate into your own applications.

The additional sample application addresses this need. It includes a non-visual object (n_wmi) that contains a method (of_QueryWMI) which issues a WQL query you supply, parses the results and returns the parsed results in an unbounded structure array. Another non-visual object (n_adapter) provides an example how you can easily extract information using WMI by obtaining information about active/enabled network adapters.

Below is a link to the Microsoft documentation on the Win32 computer system hardware classes, in case you wish explore WMI and/or experiment:

learn.microsoft.com/en-us/windows/win32/...tem-hardware-classes

This message has attachments files.
Please log in or register to see it.

Last Edit: 1 year 9 months ago by John Fauss. Reason: Added second sample app that is intended to be more useful to developers wishing to utilize WMI in their own applications.

Please Log in or Create an account to join the conversation.

Moderators: Appeon Administrator