Finding the CD drives on a system

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

Is there a way to detect how many, and what drive letters the CD/DVD drives
on a system are?

Any help is greatly appreciated.
 
Is there a way to detect how many, and what drive letters the CD/DVD
drives on a system are?

You can use Environment.GetLogicalDrives to enumerate them, and
kernel32.dll's GetDriveType to figure out what it is.

using System;
using System.Collections;
using System.Runtime.InteropServices;

public class MyClass
{
[DllImport("kernel32.dll")]
public static extern DriveType GetDriveType( string lpRootPathName );

public enum DriveType : uint
{
DRIVE_UNKNOWN = 0,
DRIVE_NO_ROOT_DIR = 1,
DRIVE_REMOVABLE = 2,
DRIVE_FIXED = 3,
DRIVE_REMOTE = 4,
DRIVE_CDROM = 5,
DRIVE_RAMDISK = 6
}

public static void Main()
{
string[] x = Environment.GetLogicalDrives();
foreach(string y in x)
{
DriveType t = GetDriveType(y);
Console.WriteLine(y + " - " + t.ToString());
}
Console.ReadLine();
}
}
 
I think the best way doing this, is the following code snippet

foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
Console.WriteLine("{0}\t{1}", drive.Name, drive.DriveType);


HTH
 
foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
Console.WriteLine("{0}\t{1}", drive.Name, drive.DriveType);

System.IO.DriveInfo doesn't compile for me... is this .NET 2.0?
 
Back
Top