How to detect insertion and removal of other USB Peripherals?

Exquisite

Member
Joined
Dec 2, 2014
Messages
5
Programming Experience
1-3
Why is it that this VB.NET code only works for detecting flash disks?

VB.NET:
Select Case m.WParam
    Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
        MsgBox("USB Inserted")
    Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE
        MsgBox("USB Removed")
End Select
What would be the possible way to detect the insertion and removal of other USB peripherals, such as mouse and keyboard? Thanks in advance
 
That would depend on what you have registered to get notified about. RegisterDeviceNotification function (Windows)
As explained:
  • with DEVICE_NOTIFY_ALL_INTERFACE_CLASSES (require type DEV_BROADCAST_DEVICEINTERFACE) "The dbcc_classguid member is ignored" and you will get notification for all device classes,
  • or with DEVICE_NOTIFY_WINDOW_HANDLE (and type DEV_BROADCAST_DEVICEINTERFACE) you have to set appropriate dbcc_classguid to get notifications for that class of devices.
 
Back
Top