如何发现USB存储设备和可写CD/DVD驱动器(C#)

Stu*_*wig 5 c# .net-2.0

如何在给定时间发现可用的任何USB存储设备和/或CD/DVD刻录机(使用C#.Net2.0).

我想向用户提供可以存储文件以便物理移除的设备选择 - 即不是硬盘驱动器.

Mar*_*ram 9

using System.IO;

DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
  if (d.IsReady && d.DriveType == DriveType.Removable)
  {
    // This is the drive you want...
  }
}
Run Code Online (Sandbox Code Playgroud)

DriveInfo类文档在这里:

http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx