The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 6 of 6

Thread: Fire event if drive inserted

  1. #1

    Fire event if drive inserted

    Is there an event that will trigger if a removable drive (or drive with certain label or something along those lines) is detected?
    Thx
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  2. #2
    On what OS? What language?


    K-Emmys-06: Best Footer; and K-Emmys-06: Most Active Member

  3. #3
    Windows and C#
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  4. #4
    I am sure there is an automated way, but I just don't know it. Instead, you can check manually for such an event. The code for getting your hard drives would be (based on what I found here):
    Code:
            public enum DriveType : int
            {
                Unknown = 0,
                NoRoot = 1,
                Removable = 2,
                Localdisk = 3,
                Network = 4,
                CD = 5,
                RAMDrive = 6
            }
    
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetDriveType(string pathName);
    
            static void Main(string[] args)
            {
                foreach (string drive in System.Environment.GetLogicalDrives())
                {
                    Console.WriteLine(drive + " " + Enum.GetName(typeof(DriveType), GetDriveType(drive)));
                }
            }
    You could then periodically check every few seconds to see if any new drives were added or removed

    Cheers!
    Kirupa

    Great, now even Kirupa is { facebooking | twittering }

  5. #5
    Thansk Kirupa!
    Do you reckon I should check every 30 seconds? I'm assuming this won't really take a hit on performance.
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  6. #6
    You could check every second if you want. Just run it on a background thread with low priority so that it doesn't block anything your main app does

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012