Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

Logical drives types and system events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andres Armengol - 05 Jul 2005 16:58 GMT
Hi,

Is there any class that watch for the logical drives installed in the
computer.
I want to enable a button in a windows form application when a USB stick is
inserted and recognised.

For the events I do a loop and always ask for the logical drives and to
differentiate from the local drive I've got this way around but I have to
know which drives are installed before a new one is inserted and I also dont
know what kind of drive it is.
_____________________________________________________________
       logicalDrives = System.IO.Directory.GetLogicalDrives()
       For Each logicalDrive In logicalDrives
           directoryInfo = New System.IO.DirectoryInfo(logicalDrive)
           If driveInfo.Exists Then
               Dim str As String
               str = driveInfo.FullName
               'Only removable drives
               If str <> "C:\" AND str <> "D:\"Then
                   found = True
                   Exit For
               End If
           End If
       Next
________________________________________________________________

I have for example the problem that when I insert a floppy disk, my code
does not notice the diference (USB stick <> Floppy)

Thanks
Mattias Sjögren - 06 Jul 2005 08:01 GMT
>Is there any class that watch for the logical drives installed in the
>computer.

Not that I'm aware of, but you can try using the native
RegisterDeviceNotification API and watch for WM_DEVICECHANGE messages.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Andres Armengol - 06 Jul 2005 11:04 GMT
It is more complicated as I though. Any way thanks for the input. I am also
reading about the System.Management namespace and the ManagementEventWatcher.
I will have a look on both ideas

> >Is there any class that watch for the logical drives installed in the
> >computer.
[quoted text clipped - 3 lines]
>
> Mattias
Willy Denoyette [MVP] - 06 Jul 2005 11:25 GMT
Yes, the Management classes are the way to go.
You can register an ManagementEventWatcher for 'Win32_USBControllerDevice'
instance arrivals, sometyhing like this will do:

....
WqlEventQuery q = new WqlEventQuery();
  q.EventClassName = "__InstanceOperationEvent";
  q.WithinInterval = new TimeSpan(0,0,3);
  q.Condition = @"TargetInstance ISA 'Win32_USBControllerDevice' ";
  w = new ManagementEventWatcher(q);
  w.EventArrived += new EventArrivedEventHandler(this.UsbEventArrived);
  w.Start(); // Start listen for events

public void UsbEventArrived(object sender, EventArrivedEventArgs e) {
... // Handle the event
}

Willy.

> It is more complicated as I though. Any way thanks for the input. I am
> also
[quoted text clipped - 11 lines]
>>
>> Mattias

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.