Link to home
Start Free TrialLog in
Avatar of valleytech
valleytechFlag for United States of America

asked on

Detect a USB device

 Hi all,
 I just wonder how I can detect a usb drive when it was just inserted to my computer. I really need it since my program will be executed each time when user inserts a usb drive to the system. Thanks.
ASKER CERTIFIED SOLUTION
Avatar of OnegaZhang
OnegaZhang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NawalKishore1976
NawalKishore1976

Hope this will help
>>add a handler to WM_DEVICECHANGE message

addition to suggestion of OnegaZhang ....

The system sends the DBT_DEVICEARRIVAL device message when a device has been inserted and becomes available.

To send the DBT_DEVICEARRIVAL device message, the system sends the WM_DEVICECHANGE message with wParam set to DBT_DEVICEARRIVAL and lParam set to the address of a DEV_BROADCAST_HDR structure identifying the device inserted.

dwData = (DWORD) lParam;

But......one problem..
there no provision by this method to detect USB device if its plugged previously or that is plugged in already...

MAHESH