Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. They're all connected via USB, so I query the WMI registry for all Win32_PnPEntitys. 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.

like image 524
Vincent Van Den Berghe Avatar asked Nov 16 '25 03:11

Vincent Van Den Berghe


1 Answers

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 :)

like image 172
Vincent Van Den Berghe Avatar answered Nov 17 '25 15:11

Vincent Van Den Berghe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!