1、使用.net管理对象(引入System.Management)
public static List<string> getDisk()
{
WqlObjectQuery wmiquery = new WqlObjectQuery("select * from Win32_LogiCalDisk");
ManagementObjectSearcher wmifind = new ManagementObjectSearcher(wmiquery);
ManagementObjectCollection queryCollection = wmifind.Get();
List<string> ls = new List<string>();
foreach (var disk in queryCollection)
{
ls.Add(disk["DeviceID"].ToString());
}
return ls;
}
2、使用驱动信息(引入System.IO)
public static List<string> getDisk()
{
var drivers = DriveInfo.GetDrives();
List<string> ls = new List<string>();
foreach (var driver in drivers)
{