[2.0] Determine CD Drive Letter
I need to prompt my users to insert a CD.
How do I determine what drive letters are CD-ROMs, so I can check for the disc?
It is very concievable that they will not know their drive letter or I'd just ask them for it. I am also avoiding opening up a drive navigator for them to pick it. We are in a industrial environment and they will have varying levels of computer knowledge.
Re: [2.0] Determine CD Drive Letter
A small console application, Add reference to System.Management library.
cs Code:
System.Management.ManagementObjectSearcher mobs = new System.Management.ManagementObjectSearcher(new System.Management.SelectQuery("select * from win32_cdromdrive"));
System.Management.ManagementObjectCollection moc = mobs.Get();
foreach(System.Management.ManagementObject mo in moc)
{
Console.WriteLine("ID: {0}", mo["Id"].ToString());
Console.Write("Name of CD inserted: ");
if(mo["volumename"] != null)
{
Console.WriteLine("{0}\n\n", mo["volumename"].ToString());
}
else
{
Console.WriteLine("No CD inserted\n\n");
}
}
Re: [2.0] Determine CD Drive Letter
I think that is a bit overkill...
I just use the GetDrives() function.
This is one of those things that takes some poking and prodding in the
language to make it do what you need it.
Here is an intermediate version of my code:
Code:
private string CheckForDisc(string pDiscNumber)
{
string strIFoundIt = "";
string strCheckForThis = "MyDisc" + pDiscNumber.Trim();
DriveInfo[] myDIArr = System.IO.DriveInfo.GetDrives();
foreach (DriveInfo myDI in myDIArr)
{
try
{
if (myDI.VolumeLabel == strCheckForThis)
strIFoundIt = myDI.Name;
}
catch (IOException ex)
{
//do nuttin
}
}
return strFoundIt;
}
Anyways, your code was helpful when I had to access the USB ports,
it got me in the correct direction.