Popular Posts

Monday, January 2, 2012

Monitoring USB devices

USB flash disk  that is data storage device that compact, small, easy to read and write but the capacity of thousands of times the size of the floppy disk is 1:44 ". These features led to a USB flash disk is very popular. Popularity of USB flash disk causes the software developer is required to support these devices. Many current software, especially multimedia player software, which includes a feature for synchronizing data with a USB flash disk device. The first step of course is how to detect if a USB device is plugged in or removed.


This article was written to answer questions about how to detect when a USB flash disk is installed or removed to a computer on the Windows operating system. Detail the question here.


WM_DEVICECHANGE


WM_DEVICECHANGE message will be sent to top-level window when there are changes to existing hardware configuration on the computer. Some of the events leading WM_DEVICECHANGE sent, one of which, is the change in the removable storage media such as CD / DVD or USB flash disk.
Message handlers can use the wParam parameter to specify the type of device change events. Some of them are:

  • DBT_DEVICEARRIVAL. Devices or media recently installed and ready for use.
  • DBT_DEVICEREMOVECOMPLETE. Device or removable media success.
  • DBT_DEVICEREMOVEPENDING. Devices or media success is delayed.
  • DBT_DEVICEQUERYREMOVE. Request permission that a device or removable media want. You can refuse a request to remove the device or media. If your application is accessing data in a file that is located in the flash disk and flash disk does not allow it unplugged, you can cancel the request by returning the value BROADCAST_DENY_REQUEST. If agreed to release the flash disk, the contents of the return value to TRUE.
  • DBT_DEVICEQUERYREMOVEFAILED. Device or removable media fails.

Technology