|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to detect removeable drive insertionHi 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 On 27 Apr 2006 02:58:06 -0700, "Steve Marshall"
<ste***@westnet.net.au> wrote: >Hi All, AFAIK, the easiest way to detect removable drive (and CD drive) media> >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 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
how to fill listview without image
EVAL function sending values to a VB.Net exe <Flags()> ENUM attibute Using Waitable Timer APIs with VB.NET. Salamander Online Decompiler v2 available Mabry FTP/NET LicenseKey ! How to change default installation to "Everyone" instead of "Just Me" Inserting HTML into a page based on conditions need some suggestions |
|||||||||||||||||||||||