Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello friends,
I use CODE::BLOCKS in Windows vista.
I would like to write a program on USB, that, when a pen drive or something is connected to the USB port my program should warn me that something is connected.
I would like to write the same in C or C++ language.
Please provide me some tips.
I think I can make it out from registry. If yes, then I would like to know what will be value of registry key before and after USB drive connected. Because I did not find any difference.
Please help me.
Posted

 
Share this answer
 
Comments
Sergey Chepurin 26-May-12 5:43am    
The OP's user name is "rasmiranjanbabu". But probably, he is known to somebody as "Sergey".
Volynsky Alex 26-May-12 13:32pm    
Sorry,
I mean rasmiranjanbabu

Regards,
Alex
It is not exactly clear to me if you want to be able to scan through the connected devices (on program startup) or detect when devices are added/removed on the fly. If you want to detect the changes, I recommend taking a look at this CodeProject article:

www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-or-Removal[^]

It is written in C++ and I found it easy to use the code for detecting when USB COM port devices are added and removed.


Soren Madsen
 
Share this answer
 
Hi
The link below might be helpful:
How to enumerate hardware devices by using SetupDi calls[^]

MSDN:Public Device Installation Functions[^]

I like using DevCon.exe in WinDDK. (Src code: WinDDK\*version\src\setup\devcon)
This should have enough info to enumerate connected devices.
http://msdn.microsoft.com/en-us/library/windows/hardware/ff544707(v=vs.85).aspx[^]

If you want to monitor the connection, you might wanna use Timer using the API above and constantly watch the changes.

Good luck,
Sean
 
Share this answer
 
Have you read this codeproject article.. It have some useful inputs for you


HIDAche - An Exercise in Hardware/Software Integration

The following link the related links in StackOverflow might help you

http://stackoverflow.com/questions/7964639/net-programming-and-interfacing-with-a-usb-device
 
Share this answer
 
v2
Comments
rasmiranjanbabu 24-May-12 9:00am    
@JimJos: I have gone through the links, but does not serve my needs.
Advise you to always search Codeproject.com first. Accidentally, there is a good article on this very topic - Simple URB (USB Request Block) Monitor[^].
But there is even better sample "USB Device Viewer" in Windows DDK (in C:\WinDDK\7600.16385.1\src\usb\usbview). But it does not constantly "monitor" ports (that functionality you could, probably, add by yourself).
P.S. I was wrong, it has option "Auto Refresh".
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900