Detecting a USB drive arrival/removal, where the drive has beenunmounted (drive letter removed)

  • Thread starter Thread starter GeneM
  • Start date Start date
G

GeneM

Hi all,

I'm creating an application tht detects when USB drives are inserted
and removed. I've overridden the WndProc method in a hidden form to
trap the WM_DEVICECHANGE messages and then inspect the WParam for
DBT_DEVICEARRIVAL, DBT_DEVICEQUERYREMOVE, and DBT_DEVICEREMOVECOMPLETE
values.

However if the Drive leter is removed for a drive, the WM_DEVICECHANGE
message is pumped but only with the DBT_DEVNODES_CHANGED parameter,
which isn't unique or a reliable way to indentify this event.


Can anyone comment or make a suggestion please?


e.g.-
if (m.Msg == WM_DEVICECHANGE) {

switch (m.WParam.ToInt32()) {

case DBT_DEVICEARRIVAL:
...
break;

case DBT_DEVICEQUERYREMOVE:
...
break;

case DBT_DEVICEREMOVECOMPLETE:
...
break;
}
}
 
Back
Top