Question

I am looking for a way to remove the physical disk 0 when the aquisition of the list of device on the computer.

the command executed is as follows:

ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
        foreach (ManagementObject moDisk in mosDisks.Get())
        {
            driveList.Items.Add(moDisk["Model"].ToString());
        }

thank you for your help.

Was it helpful?

Solution

ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
    foreach (ManagementObject moDisk in mosDisks.Get())
    {
        if(!moDisk["DeviceId"].ToString().Contains("PHYSICALDRIVE0"))
        {
            driveList.Items.Add(moDisk["Model"].ToString());
        }
    }

Or more simply, change your WQL to this:

SELECT * FROM Win32_DiskDrive WHERE NOT NAME LIKE '%PHYSICALDRIVE0'

OTHER TIPS

How is it that you can reliably recognise physical disk drive 0?

If you comment out the adding to the drive list combobox and instead add in the code fragment below you can see the properties of the ManagementObject and decide which to use:

foreach(var prop in moDisk.Properties)  
{  
  Console.WriteLine("{0}: {1}", prop.Name, prop.Value);  
}  

For example (I haven't got enough drives to be certain) you may want to exclude Index 0 which you can either do by checking within the loop and not adding to the combobox or by updating your select:

select * from Win32_DiskDrive where Index <> 0

Also you can just select Model rather than *

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top