0

Background:

I'm using a third-party library to read a smart card used as an ID card.

This library only supports a method to read the card. It doesn't throw events when the card is inserted into the reader. As a result, currently, I can only have the card read when a button is clicked. I want to remove this requirement of clicking.

Requirement:

When the ID card is inserted into the reader, the software automatically adds an item to "Devices and Printers" called "ID Card". How can I get a notification when this item is added?

Current findings:

This excellent answer successfully triggers an event when the USB reader is inserted into the computer. It does not, however, trigger an event when the card is inserted into the reader (even though it somehow appears in the "Devices and Printers" list.

This answer lists all the USB devices connected to the computer. It somehow lists more devices than are connected to the computer (8 when there are only 3 devices + the card). It also does not detect the card - the number remains the same whether or not the card is inserted into the reader.

How can I read this "Devices and Printers" list? And how can I detect when a new item is added to this list?

Community
  • 1
  • 1
Zesty
  • 2,840
  • 8
  • 30
  • 60
  • 1
    You have to listen for the Plug and Play event. Not that easy to do in C#, the framework is no support at all for the SetupAPI. Use http://stackoverflow.com/a/2061741/17034 – Hans Passant Aug 17 '16 at 10:17
  • Thank you! This worked for me by instead detecting when the smart card got added to "Smart Cards" under devices - I should have thought of that before the "Devices and Printers" route. Should I close this as a duplicate (not sure - as this may not be considered a duplicate) or will you post your comment as the answer? – Zesty Aug 17 '16 at 11:47

0 Answers0