如何从未驻留在 USB 上的 C# 程序中检测 USB 驱动器字符?该程序应驻留在系统中,如果连接了多个 USB,则首先应能够获取制造商名称。
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.DriveType == DriveType.Removable)
{
// Code here
}
}
获取USB驱动器制造商可能会更加困难,您可能需要使用WMI。
编辑:以下是两个有关读取USB驱动器信息的链接:
List<string> list_usb= DriveInfo.GetDrives().Where(d => d.DriveType.ToString() == "Removable").Select(d => d.Name).ToList();
foreach(var i in list_usb)
{
Console.WriteLine(i);
}