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

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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top