USB passcode

I was wondering how to make a program that when I plug in my USB drive the console then spits out a specific passcode that is set in the USB itself.(i am on windows 10 with visual studio 2017)
Take a look at EnumPorts(...):

https://docs.microsoft.com/en-us/windows/desktop/printdocs/enumports

For a first try you can enumerate these ports and try to connect to them. When the connection succeed you found your device.
Thanks for your help, but if i am being honest i have no idea how to use enums but i am doing more research now.
closed account (z05DSL3A)
Dawsoncodes,

EnumPorts is for printer ports on a server, I don't think that is what you want.

I'm assuming that you want your program running. It gets notified when a USB drive is plugged in, so it can retrieve and display the passcode. For that you probably want the RegisterDeviceNotification function.

https://docs.microsoft.com/en-us/windows/desktop/DevIO/registering-for-device-notification

If you didn't want a visibly running program, you may want to look at creating a Windows service.

Either way it's not a straight forward task.
@Grey Wolf

I'm using EnumPorts(...). It shows all possible ports not only for the printer. That much that I have to filter the com: ports.
closed account (z05DSL3A)
coder777,
I'll have to give it a look. I've used it for com port enumeration.
Topic archived. No new replies allowed.