以下是示例代码:
先要引用System.Management.dll,
using System.Management;
SelectQuery query =
new SelectQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(query);
foreach (ManagementBaseObject envVar in searcher.Get())
{
this.listBox1.Items.Add(envVar["Name"].ToString());
}
new SelectQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(query);
foreach (ManagementBaseObject envVar in searcher.Get())
{
this.listBox1.Items.Add(envVar["Name"].ToString());
}
如果查询语句中的DriveType 为2,会得到软驱,如果为5,会得到光驱。