0

コンピューター上のデバイスのリストを取得するときに、物理ディスク0を削除する方法を探しています。

実行されるコマンドは次のとおりです。

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

ご協力ありがとうございました。

4

2 に答える 2

0
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'
于 2012-03-09T10:18:53.153 に答える
0

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 *

于 2012-03-09T10:27:08.840 に答える