Results 1 to 3 of 3

Thread: [2.0] Determine CD Drive Letter

  1. #1

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    [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.
    Merry Christmas

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2.0] Determine CD Drive Letter

    A small console application, Add reference to System.Management library.
    cs Code:
    1. System.Management.ManagementObjectSearcher mobs = new System.Management.ManagementObjectSearcher(new System.Management.SelectQuery("select * from win32_cdromdrive"));
    2.  
    3. System.Management.ManagementObjectCollection moc = mobs.Get();
    4.  
    5. foreach(System.Management.ManagementObject mo in moc)
    6. {
    7.     Console.WriteLine("ID: {0}", mo["Id"].ToString());
    8.     Console.Write("Name of CD inserted: ");
    9.  
    10.     if(mo["volumename"] != null)
    11.     {
    12.         Console.WriteLine("{0}\n\n", mo["volumename"].ToString());
    13.     }
    14.     else
    15.     {
    16.         Console.WriteLine("No CD inserted\n\n");
    17.     }
    18. }
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    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.
    Merry Christmas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width