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)
{
if (driver.DriveType != DriveType.Fixed)
{
continue;
}
ls.Add(driver.Name);
}
return ls;
}
3、使用环境信息
public static List<string> getDisk()
{
String[] drives = Environment.GetLogicalDrives();
return new List<string>(drives);
}
最后
以上就是缓慢灰狼最近收集整理的关于C# 获取系统盘符的全部内容,更多相关C#内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复