How can I attach a filter to a USB drive?

If the device is already present in the system and has some drive letter, then you just attach the filter to the drive as you do with a regular drive.

However, if you want to track all (or any) inserted USB drives, you need to be notified when the device is attached to the system (a USB disk is plugged to the computer). You can do this by handling the WM_DEVICECHANGE window message or by using the RegisterDeviceNotification function of the Windows API.

The latter case is useful when you don't have a window handle (e.g., in the service application). When using RegisterDeviceNotification, you will need to set a filter in order to specify the devices you want to track. An internet search for "RegisterDeviceNotification" will reveal several useful articles, such as the one on CodeProject.

CBFS Filter 3 includes the OnFilterAttachToFsVolume event, which lets you know when the new device appears in the system. Different from the way mentioned above, this is an alternative way for tracking a device attachment.

Ready to get started?

Learn more about Callback Technologies or download a free trial.

Download Now