By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

How to detect removeable drive insertion

P: n/a
Hi All,

Apologies if this has come up before, but how can I set up something
that will notify me when a removeable drive (like a USB drive or
CompactFlash card) is inserted into its slot? Ideally I would like
some sort of event that would call my code when it happens. The
FileSystemWatcher object doesn't seem able to do this, unless I am
missing something.

Thanks

Apr 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 27 Apr 2006 02:58:06 -0700, "Steve Marshall"
<st****@westnet.net.au> wrote:
Hi All,

Apologies if this has come up before, but how can I set up something
that will notify me when a removeable drive (like a USB drive or
CompactFlash card) is inserted into its slot? Ideally I would like
some sort of event that would call my code when it happens. The
FileSystemWatcher object doesn't seem able to do this, unless I am
missing something.

Thanks


AFAIK, the easiest way to detect removable drive (and CD drive) media
insertion is to check the "IsReady" value of the drive.

What I do: At startup, I loop through the "DriveInfo.GetDrives()"
return and look for "DriveType.Removable" (excluding drive 0 which is
assumed to be a floppy drive if not a "DriveType.Fixed"). If a
removable drive is found, I check the "IsReady" value. I use a
GenericDictionary(Of Integer, Boolean) to which the removable drive
index and IsReady values are added. Start a timer.

The timer loops through the 3 or 4 items in the dictionary which hold
the removable drive indicies(keys) and IsReady values (Items). For
each key, the IsReady value is checked and compared to the existing
item value for that key. If the item value has changed, item value is
updated. If the change is from False to True, media was inserted - do
some other work. If the change was from True to False, media was
removed - probably ignore.

Gene
Apr 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.