0

Based on my query How to find the true CD-Rom drive letter when a virtual drive is also installed?

And the suggestion I got from here How to identify if a drive is virtual or physical

I'd like to just fill a Combo Box of virtual drive letters when the DeviceID string contains SCSI, I've tested both my virtual drives and they do have SCSI listed against them.

The first 4 characters in the answer from the example in the suggested link

string driveLetter = "G";
        ManagementObjectSearcher diskQuery = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_CDROMDrive WHERE Drive='{0}:'", driveLetter));
        ManagementObject diskResult = diskQuery.Get().OfType<ManagementObject>().SingleOrDefault();
        string deviceID = null;
        if (diskResult != null)
            deviceID = (string)diskResult["DeviceID"];
        MessageBox.Show(deviceID);

Show SCSI, so I thought I could do something like this

ManagementObjectSearcher diskQuery = new ManagementObjectSearcher(String.Format("select * from Win32_CDROMDrive Where DeviceID Like '%SCSI%'"));
        ManagementObject diskResult = diskQuery.Get().OfType<ManagementObject>().SingleOrDefault();
        string deviceID = null;
        if (diskResult != null)
            deviceID = (string)diskResult["DeviceID"];
        MessageBox.Show(deviceID);  

However it doesn't work, I just get an Invalid Operation Exception.

What I'm trying to do is this

ComboBox cbVirtual = new ComboBox();
    var vdrives = DriveInfo.GetDrives();
    foreach (var drive in vdrives)
        if (drive.DriveType == DriveType.CDRom)
        {
            If the deviceID string contains SCSI
            {
                Fill the Combo box with the drive letter/s
            }
        }

Appreciate some help - cheers.

Community
  • 1
  • 1
Exception
  • 71
  • 1
  • 9

1 Answers1

0

you need to

string driveLetter = "G";

ComboBox.ObjectCollection items = vdrives.Items;
Items.Add(driveLetter);

that's how you add objects to the Combo Box.

Johan
  • 262
  • 1
  • 15
  • Thanks Johan, but that is not what I'm after. I want the code to pick up the drives with DeviceID text of SCSI. It has to be automatic not picked up by adding driveLetter = "G"; Each user may have a different drive letter. – Exception Feb 28 '15 at 05:30