473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to detect removeable drive insertion

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
1 5565
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Viper99 | last post by:
Need to detect (receive notification) for the insertion/removal of PCMCIA devices on Windows 2000/XP in a C# .Net application. Was able to do this in ATL COM app using CWnd::OnDeviceChange().
3
by: Richard H. Rowson | last post by:
Does anyone know of a way to detect which drive is a Zip drive (I guess in the same way that the various system variables can be queried) ?>Thanks
4
by: S. Graefner | last post by:
I have been unable to locate anywhere the answer to my problem. I would like to be able to download/import a single record. This record is stored in many different related (one to one) tables. I...
9
by: Paul Steele | last post by:
I am writing a C# app that needs to periodically poll for cdroms and usb storage device insertions. I've looked at the WMI functions but haven't found anything all that useful. The closest is...
4
by: sanjana | last post by:
hi can anyone help me with this i want to write a code in c#.net which detects usb storage and media card insertion can anyone help me with this?? thanx
4
by: sanjana | last post by:
hi i m using the win32_diskdrive class for detecting a memory card insertion and removal..and this class detects memory card(sd card..etc) insertion removal from the device the deviceid...
3
by: Bob | last post by:
Is there a simple approach in vb.net to search logical drives to determine which are removeable media types (e.g., a zip drive or the A drive)? I've used FSO with VB6 for this and am now searching...
2
by: Chad | last post by:
I am in the process of writing an application that detects the insertion of a pen drive, and if a specific folder structure exists, it shows a form containing data. The problem is that when I...
4
by: Academia | last post by:
I don't suppose there is any way to tell if there is a floppy in a floppy drive without activating the drive and causing it to make a noise if there is no floppy in the drive. Is there? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.