How to obtain drive letters without checking the diskette?
-
I tried two ways of obtaining drive letters, one using
Directory.GetDriveNames()
and the other usingManagementObjectCollection
. 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. -
I tried two ways of obtaining drive letters, one using
Directory.GetDriveNames()
and the other usingManagementObjectCollection
. 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.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
-
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
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.
-
I tried two ways of obtaining drive letters, one using
Directory.GetDriveNames()
and the other usingManagementObjectCollection
. 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.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 -
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.
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
-
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
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:.
-
I tried two ways of obtaining drive letters, one using
Directory.GetDriveNames()
and the other usingManagementObjectCollection
. 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. -
Check the type of the drive. If it's a removable drive you should skip it. --- b { font-weight: normal; }
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.
-
I tried two ways of obtaining drive letters, one using
Directory.GetDriveNames()
and the other usingManagementObjectCollection
. 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.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. -
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.This works on .NET 2.0, but I have to solve the problem on .NET 1.1 :((