473,782 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
FileSystemWatch er object doesn't seem able to do this, unless I am
missing something.

Thanks

Apr 27 '06 #1
1 5593
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
FileSystemWatc her 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.GetD rives()"
return and look for "DriveType.Remo vable" (excluding drive 0 which is
assumed to be a floppy drive if not a "DriveType.Fixe d"). If a
removable drive is found, I check the "IsReady" value. I use a
GenericDictiona ry(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
1390
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
2306
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
1474
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 have saved a single record to Excell and then to a floppy by using a query, to save the parts of the record I want then "Save as" "Excell". The problem is being able to take it from the floppy/USB drive and import it to the same, but in a different...
9
37210
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 Win32_DiskDrive, but it doesn't seem to return any information on cdrom devices. I suspect there might be a Win32 API call, but I haven't found any info yet using Google. Is there a way to achieve this in C#?
4
5808
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
25227
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 attribute gives me \\.\PHYSICALDRIVE0 or \\.\PHYSICALDRIVE1 etc.. i m trying to get the drive name say(c: or d: ...etc)from the device
3
1396
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 for a vb.net replacement. -- Thanks, Bob
2
1506
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 insert the pen drive on some machines running Windows XP, a windows explorer window appears containing the contents of the pen drive. This window covers my application's window, even if my application window opens a few seconds later. How do I...
4
1705
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? Thanks
0
10311
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8967
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.