Reputation: 4922
I can use devcon.exe
and list all available classes:
C:\devcon classes
Listing 111 setup classes.
XboxComposite : Xbox Peripherals
RemotePosDevice : POS Remote Device
DigitalMediaDevices : Digital Media Devices
PrintQueue : Print queues
…
So from that I can see there are 111 setup classes. However, when I query for Win32_PnPEntity
:
var query = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity");
var results = query.Get();
var set = new HashSet<string>();
foreach(var device in results)
{
var className = (string)device.GetPropertyValue("PNPClass");
set.Add(className)
}
var count = set.Count; // 25 <---- not 111
I get 25, not 111. So My query is clearly a subset of what's actually available to the machine which makes sense. The classes that output from devcon classes
line up with the PNPClass
property value, so I assume they are the same.
So there must be a way to fetch all the available PNPClass
's unless devcon.exe
just hardcodes that list it outputs with devcon classes
I would like to generate this list myself programmatically, not invoking devcon classes
as a subprocess and parsing it's output.
Upvotes: 1
Views: 1995
Reputation: 1229
Unfortunately, Win32_PNPEntity doesn't map exactly to the data you would get from devcon. Devcon gives you all the available classes on the system including System, filter, PNP, etc. Win32_PNPEntity is just the plug and play devices. Win32_PNPEntity data also depends on what hardware is currently connected.
devcon is outputting all the data from the subkeys in "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class" where there is no name/value called NoUseClass=1. It's displaying the Class and ClassDesc values. The ClassDesc value could be either a literal string, a reference to a value in a .inf or a reference from a dll so outputting that info would take some work.
What are you trying to do with that data? Maybe there is another way you can get the info you need? If you are just trying to get the class info for connected PNP devices then your existing code should get the info you need.
Upvotes: 1