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.