I have an app that uses a smart card reader. A user may have several identical readers, and their system names, as returned by SCardListReaders
, differ in number suffix, for instance "OMNIKEY CardMan 5x21 0" and "OMNIKEY CardMan 5x21 1". User can set up the the reader for the app. If during work user puts the smart card in another reader the app will not react.
The problem is, I have reports that after the Windows restart the readers can be shuffled as well. The one that had "0" in the name before can now have "1". I have no influence on this. After the shuffle happens the user must choose the reader again in the app, and I want to fix this somehow so that user does not have to do anything.
First I was toying with SCardGetAttrib
and SCARD_ATTR_VENDOR_IFD_SERIAL_NO
, but this parameter does not return a unique string for every reader in the world. For instance it may return "12345678" for all readers of the same certain type.
I am now looking at SetupAPI function SetupDiGetDeviceRegistryProperty
. I can list all USB devices, and parameters SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
and SPDRP_LOCATION_PATHS
seem to be unique and I hope fixed in the system. If reader is not a USB device then I'll rely just on the name, as I am now. Problem is, I can't deduce from reader name which USB device I should be looking at. None of the SPDRP_
parameters will give me a reader name, and I need the name that I can give to SCardConnect
.
How can I get from reader name to corresponding HDEVINFO
that I can give to SetupDiGetDeviceRegistryProperty
? Alternatively, is there another way to distinguish between smart card readers of the same type, which is reliable even after Windows restart?