简体   繁体   English

如何从c#应用程序中检测USB驱动器号?

[英]How do I detect a USB drive letter from a c# application?

How to detect the USB drive letter from c# program which is not residing in the USB? 如何检测不在USB中的c#程序的USB驱动器盘符? The program should reside in the system, if multiple USB's are connected then i should first able to get the manufacturer name also. 该程序应驻留在系统中,如果连接了多个USB,那么我首先应该获得制造商名称。

This will get all of the removable drives attached (including USB drives): 这将连接所有可移动驱动器(包括USB驱动器):

foreach (DriveInfo drive in DriveInfo.GetDrives())
{
    if (drive.DriveType == DriveType.Removable)
    {
        // Code here
    }
}

Getting the USB drive manufacturer may be more difficult, and you may need to use WMI. 获取USB驱动器制造商可能会更困难,您可能需要使用WMI。

Edit : Here are 2 links on reading USB drive information: 编辑 :以下是有关读取USB驱动器信息的2个链接:

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);
            }

you can try this. 你可以试试这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM