Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to obtain drive letters without checking the diskette?

How to obtain drive letters without checking the diskette?

Scheduled Pinned Locked Moved C#
tutorialquestion
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Libor Tinka
    wrote on last edited by
    #1

    I tried two ways of obtaining drive letters, one using Directory.GetDriveNames() and the other using ManagementObjectCollection. In both cases, my app checked the A drive and sometimes also D drive. This caused that terrible noise from diskette drive or/and a "no media in drive" dialog appeared every time the application is launched. I can just skip the problematic "A" and "D" drives, but this is a dirty solution, because not all users have A,C,D drive letters.

    T G S 4 Replies Last reply
    0
    • L Libor Tinka

      I tried two ways of obtaining drive letters, one using Directory.GetDriveNames() and the other using ManagementObjectCollection. In both cases, my app checked the A drive and sometimes also D drive. This caused that terrible noise from diskette drive or/and a "no media in drive" dialog appeared every time the application is launched. I can just skip the problematic "A" and "D" drives, but this is a dirty solution, because not all users have A,C,D drive letters.

      T Offline
      T Offline
      Tom Wright
      wrote on last edited by
      #2

      I would have to disagree....a little on that. Most computers come with a floppy, a harddrive, and a CD-ROM. If so they will always be A, C, D respectively. While you can purchase some computers without a floppy or a CD-ROM, almost 90% of the time you will not. Why? How else will you install the OS is need be without removing the harddrive? Tom Wright tawright915@yahoo.com

      D 1 Reply Last reply
      0
      • T Tom Wright

        I would have to disagree....a little on that. Most computers come with a floppy, a harddrive, and a CD-ROM. If so they will always be A, C, D respectively. While you can purchase some computers without a floppy or a CD-ROM, almost 90% of the time you will not. Why? How else will you install the OS is need be without removing the harddrive? Tom Wright tawright915@yahoo.com

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #3

        Floppies are becoming sparse on newer machines, many oems are including an X-in-1 card reader instead. A bootable CD will install the OS without need for a floppy. Enough are also putting recovery data on a 2nd partition instead of, or in addition to a floppy that even on oem boxes assuming D for the CD is chancy. Self build machines often have multiple HDs as well, my personal machine has cd drives at H and I due to partition based data segragation and multiple harddrives.

        T 1 Reply Last reply
        0
        • L Libor Tinka

          I tried two ways of obtaining drive letters, one using Directory.GetDriveNames() and the other using ManagementObjectCollection. In both cases, my app checked the A drive and sometimes also D drive. This caused that terrible noise from diskette drive or/and a "no media in drive" dialog appeared every time the application is launched. I can just skip the problematic "A" and "D" drives, but this is a dirty solution, because not all users have A,C,D drive letters.

          T Offline
          T Offline
          Tom Wright
          wrote on last edited by
          #4

          if nothing else try this: try { string[] drives = System.IO.Directory.GetLogicalDrives(); foreach (string str in drives) { System.Console.WriteLine(str); } } catch (System.IO.IOException) { System.Console.WriteLine("An I/O error occurs."); } catch (System.Security.SecurityException) { System.Console.WriteLine("The caller does not have the " + "required permission."); } Tom Wright tawright915@yahoo.com

          1 Reply Last reply
          0
          • D Dan Neely

            Floppies are becoming sparse on newer machines, many oems are including an X-in-1 card reader instead. A bootable CD will install the OS without need for a floppy. Enough are also putting recovery data on a 2nd partition instead of, or in addition to a floppy that even on oem boxes assuming D for the CD is chancy. Self build machines often have multiple HDs as well, my personal machine has cd drives at H and I due to partition based data segragation and multiple harddrives.

            T Offline
            T Offline
            Tom Wright
            wrote on last edited by
            #5

            I agree that floppies are going out the window. With the flash drive being the choice portable data transport. However CD-ROMs will be around for quite a while and since I never said that all machine have them, there are the select few who do not order them with their machines. Heck I even had a PC that had no floppy, harddrive, or CD-ROM. It had a boot ROM on the network card and booted from a boot file on the network. That was back awhile. No sure if they still do that. Tom Wright tawright915@yahoo.com

            D 1 Reply Last reply
            0
            • T Tom Wright

              I agree that floppies are going out the window. With the flash drive being the choice portable data transport. However CD-ROMs will be around for quite a while and since I never said that all machine have them, there are the select few who do not order them with their machines. Heck I even had a PC that had no floppy, harddrive, or CD-ROM. It had a boot ROM on the network card and booted from a boot file on the network. That was back awhile. No sure if they still do that. Tom Wright tawright915@yahoo.com

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              Tom Wright wrote:

              However CD-ROMs will be around for quite a while and since I never said that all machine have them, there are the select few who do not order them with their machines. Heck I even had a PC that had no floppy, harddrive, or CD-ROM. It had a boot ROM on the network card and booted from a boot file on the network. That was back awhile. No sure if they still do that.

              True. My point was that you can't just assume the CD drive is D:.

              1 Reply Last reply
              0
              • L Libor Tinka

                I tried two ways of obtaining drive letters, one using Directory.GetDriveNames() and the other using ManagementObjectCollection. In both cases, my app checked the A drive and sometimes also D drive. This caused that terrible noise from diskette drive or/and a "no media in drive" dialog appeared every time the application is launched. I can just skip the problematic "A" and "D" drives, but this is a dirty solution, because not all users have A,C,D drive letters.

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Check the type of the drive. If it's a removable drive you should skip it. --- b { font-weight: normal; }

                L 1 Reply Last reply
                0
                • G Guffa

                  Check the type of the drive. If it's a removable drive you should skip it. --- b { font-weight: normal; }

                  L Offline
                  L Offline
                  Libor Tinka
                  wrote on last edited by
                  #8

                  Yes, but I can't check the type of drive without obtaining the collection of drives: ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk "); ManagementObjectCollection queryCollection = query.Get(); after query.Get() on the second line, the A drive is checked even when there is no diskette.

                  1 Reply Last reply
                  0
                  • L Libor Tinka

                    I tried two ways of obtaining drive letters, one using Directory.GetDriveNames() and the other using ManagementObjectCollection. In both cases, my app checked the A drive and sometimes also D drive. This caused that terrible noise from diskette drive or/and a "no media in drive" dialog appeared every time the application is launched. I can just skip the problematic "A" and "D" drives, but this is a dirty solution, because not all users have A,C,D drive letters.

                    S Offline
                    S Offline
                    Steve Hansen
                    wrote on last edited by
                    #9

                    You can always use this: static public void Main(string[] args) { // Drives are only possible from A: till Z: for (char driveLetter = 'A'; driveLetter <= 'Z'; driveLetter++) { DriveInfo drive = new DriveInfo(driveLetter.ToString()); switch (drive.DriveType) { case DriveType.NoRootDirectory: // No drive break; default: Console.WriteLine("Found drive at " + drive + " of type " + drive.DriveType); break; } } } It will only make the annoying noise when you access the properties of the drive instance. bool ready = drive.IsReady; Like that.

                    L 1 Reply Last reply
                    0
                    • S Steve Hansen

                      You can always use this: static public void Main(string[] args) { // Drives are only possible from A: till Z: for (char driveLetter = 'A'; driveLetter <= 'Z'; driveLetter++) { DriveInfo drive = new DriveInfo(driveLetter.ToString()); switch (drive.DriveType) { case DriveType.NoRootDirectory: // No drive break; default: Console.WriteLine("Found drive at " + drive + " of type " + drive.DriveType); break; } } } It will only make the annoying noise when you access the properties of the drive instance. bool ready = drive.IsReady; Like that.

                      L Offline
                      L Offline
                      Libor Tinka
                      wrote on last edited by
                      #10

                      This works on .NET 2.0, but I have to solve the problem on .NET 1.1 :((

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups