在C#中怎样判断驱动器是软驱还是光驱或硬盘

youlong34 2004-08-26 02:50:41
在C#中用Directory.GetLogicalDrives()能得到盘符,可是怎样才能区分每个盘符对应的是软驱还是光驱或硬盘呢?请多指教!!!
...全文
199 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
triout 2004-09-03
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3027/3027103.xml?temp=.8991053
暗石绿 2004-08-26
  • 打赏
  • 举报
回复
using System.Management;

const int Removable = 2;
const int LocalDisk = 3;
const int Network = 4;
const int CD = 5;

ManagementObjectCollection queryCollection = getDrives();
foreach ( ManagementObject mo in queryCollection)
{
switch (int.Parse( mo["DriveType"].ToString()))
{
case Removable: //removable drives
imageIndex = (int)FileImages.FLOPPYDISK;
break;
case LocalDisk: //Local drives
imageIndex = (int)FileImages.LOCALDISK;
break;
case CD: //CD rom drives
imageIndex = (int)FileImages.CDDISK;
break;
case Network: //Network drives
imageIndex = (int)FileImages.Network;
break;
default: //defalut to folder
imageIndex = (int)FileImages.FILE_IMAGE_DEFAULT;
break;
}
//
// show the drive in the ListView
//
listView.Items.Add( mo["Name"].ToString() , imageIndex );
}

/// <summary>
/// 获取磁盘上的目录
/// </summary>
/// <returns></returns>
public ManagementObjectCollection getDrives()
{
//get drive collection
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();

return queryCollection;
}

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧