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

左心房为你撑大大i 提交于 2019-12-06 15:33:16

I found the Device Class GUID on MSDN: {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. 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. 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).

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. Eg. in 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 :-)).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!