valleytech
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hope this will help
Hope this will help.
http://www.codeproject.com/w2k/usbdisks.asp
http://www.codeproject.com/w2k/usbdisks.asp
>>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
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