【发布时间】:2018-11-28 20:09:57
【问题描述】:
我可以使用devcon.exe 并列出所有可用的类:
C:\devcon classes
Listing 111 setup classes.
XboxComposite : Xbox Peripherals
RemotePosDevice : POS Remote Device
DigitalMediaDevices : Digital Media Devices
PrintQueue : Print queues
…
因此我可以看到有 111 个设置类。然而,当我查询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
我得到的是 25,而不是 111。所以我的查询显然是机器实际可用内容的一个子集,这是有道理的。从devcon classes 输出的类与PNPClass 属性值一致,所以我假设它们是相同的。
所以必须有一种方法来获取所有可用的PNPClass,除非devcon.exe 只是硬编码列出它与devcon classes 输出的内容
我想自己以编程方式生成此列表,而不是调用 devcon classes 作为子进程并解析它的输出。
【问题讨论】: