Introduction

In Part 1, I have demonstrated how to enumerate device classes. Now let us see how to enumerate devices of the class.

Device enumeration

First of all, let us look again at the picture with Device Manager information. It is easy - Device Manager enumerate devices when we expand the tree for device class.

The idea of device enumeration is not difficult for understanding:

Get class Guid using device class name (SetupDiClassGuidsFromNameA function)

Get device info set for device class (SetupDiGetClassDevsA function)

Get device info data for every device (SetupDiGetClassDevsA function, second parameters for this function is sequential device index in the device class, so call this function in circle with device index = 0, 1, etc.).

Get device name from Registry via SetupDiGetDeviceRegistryPropertyA function.

Below you see code in C# that will enumerate devices for selected device class for PC.

classname - the name of device class. You can use application from previous article to find correct device class name. After running application you can see devices for any device class on your PC.

Summary

Now we can join code from the first article and this article, add information about devices (for example, resources like IRQs, ports, etc) and put it in the Windows Forms application. But it is a subject for Part 3.

Share

About the Author

I am C++ Builder developer. I am interesting in WMI, Shell, some deep COM interface. Beside these I am Brainbench Win32 API Master.Now I very like Microsoft .NET and C#. I made some firsts OPOS drivers for Ukrainian fiscal printers.