简体   繁体   English

如何通过WMI将所有智能卡读卡器安装到系统上?

[英]How do I get all the smart card readers on my system via WMI?

I want to get the DeviceID and Service of all PCSC smart card readers on my system using WMI. 我想使用WMI获取系统上所有PCSC智能卡读卡器的DeviceID和服务。 They're all connected via USB, so I query the WMI registry for all Win32_PnPEntity s. 它们都是通过USB连接的,因此我在WMI注册表中查询所有Win32_PnPEntity But I have no clue how to determine which devices are 'card readers'. 但是我不知道如何确定哪些设备是“读卡器”。 Here's what I already have: 这是我已经拥有的:

ManagementObjectSearcher mos =
new ManagementObjectSearcher(@"\root\cimv2", @"Select * From Win32_PnPEntity");

ManagementObjectCollection mob = mos.Get();

foreach (ManagementObject mo in mob)
{
    Console.WriteLine("DeviceID: " + mo["DeviceID"].ToString());
    Console.WriteLine("Service: " + mo["Service"].ToString());
}

I can't just filter on the device name, there's different brands/models of readers, and there's no common denominator. 我不能只过滤设备名称,读者的品牌/型号不同,也没有共同点。 In the Device Manager they're all grouped under 'smart card readers', so there must be a(nother) way. 在设备管理器中,它们都被分组在“智能卡读卡器”下,因此必须有另一种方法。

I found the Device Class GUID on MSDN : {50dd5230-ba8a-11d1-bf5d-0000f805f530} 我在MSDN上找到了设备类GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}

 Smart Card Readers Class = SmartCardReader ClassGuid = {50dd5230-ba8a-11d1-bf5d-0000f805f530} This class includes smart card readers. 

So finally I came up with this: 所以最后我想到了这个:

ManagementObjectSearcher mos = new ManagementObjectSearcher(@"\root\cimv2",
@"SELECT* FROM Win32_PnPEntity WHERE ClassGuid = '{50DD5230-BA8A-11D1-BF5D-0000F805F530}'");

Which seems to give me what I want :) 这似乎给了我我想要的:)

I don't have any smart card readers here, so this is theoretical: 我在这里没有任何智能卡读卡器,因此这是理论上的:

  • What is the actual type ( __CLASS property) of the returned instances. 返回的实例的实际类型( __CLASS属性)是什么。 If a subtype, maybe looking for further instances of that type will help). 如果是子类型,则可能需要寻找该类型的其他实例)。

  • What associations exist for the smart card devices: 智能卡设备存在哪些关联:

     associators of {__RELPATH} 

    where __RELPATH is the same named property from the Win32_PnPEntity instance. 其中__RELPATH是Win32_PnPEntity实例中的相同命名属性。 Also include associators of the associators. 还包括关联者的关联者。

    Note that most associated instances will represent things like the USB host/hub device, but others can be other aspects of the device (like a HDD will have both a Win32_PhysicalDisk instance in addition to a Win32_PnPEntity ). 请注意,大多数关联的实例将代表USB主机/集线器设备之类的东西,但其他实例可能是该设备的其他方面(例如HDD除了Win32_PnPEntity之外还将具有Win32_PhysicalDisk实例)。

Also, to speed exploring the WMI types and objects I would suggest one of the console or GUI tools, this will be much easier than writing C# code. 另外,为了加快探索WMI类型和对象的速度,我建议使用控制台或GUI工具之一,这比编写C#代码要容易得多。 Eg. 例如。 in PowerShell: 在PowerShell中:

gwmi -query "select * from Win32_PnpEntity" | ft -autosize __RELPATH, DeviceID

easier to work with than the C# code (however it will need a very wide console window :-)). 比C#代码更容易使用(但是它需要一个非常宽的控制台窗口:-)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM