C# 获取本地电脑所有的盘符
2021-05-05 21:27
标签:fixed 驱动 bsp default logical new ids 目录 ret C# 获取本地电脑所有的盘符 话不多说,直接上菜: switch (int.Parse(mo["DriveType"].ToString())) } C# 获取本地电脑所有的盘符 标签:fixed 驱动 bsp default logical new ids 目录 ret 原文地址:http://www.cnblogs.com/magic-xxj/p/7677068.html
public List
{
List
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
{
case (int)DriveType.Removable: //可以移动磁盘
{
//MessageBox.Show("可以移动磁盘");
deviceIDs.Add(mo["DeviceID"].ToString());
break;
}
case (int)DriveType.Fixed: //本地磁盘
{
//MessageBox.Show("本地磁盘");
deviceIDs.Add(mo["DeviceID"].ToString());
break;
}
case (int)DriveType.CDRom: //CD rom drives
{
//MessageBox.Show("CD rom drives ");
break;
}
case (int)DriveType.Network: //网络驱动
{
//MessageBox.Show("网络驱动器 ");
break;
}
case (int)DriveType.Ram:
{
//MessageBox.Show("驱动器是一个 RAM 磁盘 ");
break;
}
case (int)DriveType.NoRootDirectory:
{
//MessageBox.Show("驱动器没有根目录 ");
break;
}
default: //defalut to folder
{
//MessageBox.Show("驱动器类型未知 ");
break;
}
}
return deviceIDs;
}