Determining which Drive is the CD-ROM drive

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the best way in .NET to determine which drive is the CD-ROM?
 
Hi,

To do this with out doing any interop of your own you could use WMI. The
following example should get you started, it will list the CD/DVD drive
names in the output window.

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select Name from Win32_LogicalDisk where
DriveType=5");
foreach(ManagementObject obj in searcher.Get())
{
System.Diagnostics.Debug.WriteLine(obj["Name"]);
}

Hope this helps
 
Thanks Chris.
I also found that this way works using Interop.

// From Winbase.h
public enum DriveType : int
{
Unknown = 0,
NoRoot = 1,
Removable = 2,
Localdisk = 3,
Network = 4,
CD = 5,
RAMDrive = 6
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
protected static extern int GetDriveType(string lpRootPathName);

Chris Taylor said:
Hi,

To do this with out doing any interop of your own you could use WMI. The
following example should get you started, it will list the CD/DVD drive
names in the output window.

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select Name from Win32_LogicalDisk where
DriveType=5");
foreach(ManagementObject obj in searcher.Get())
{
System.Diagnostics.Debug.WriteLine(obj["Name"]);
}

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
Oldman said:
What is the best way in .NET to determine which drive is the CD-ROM?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top