C#仅获取笔式驱动器列表而不是其他设备 [英] c# get pen drive list only not other divice

查看:86
本文介绍了C#仅获取笔式驱动器列表而不是其他设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我可以将所有USB驱动器的列表放入下拉列表中.
但是,我仅需要连接到系统的笔式驱动器的列表.我不想将其他连接的设备添加到计算机.这些设备包括:手机,相机,USB HDD,USB CD/DVD驱动器等.

我需要尽快解决方案,因为如果不这样做,我将无法进入应用程序的下一步.


这是代码

Hello All,

I am able to get the list of all USB drives into a dropdown.
But I only need the list of attached Pen Drives to a system only. I do not want to add the other attached devices to the computer. The devices like : Mobile phones, Camera, USB HDD, USB CD/DVD drive etc.

I need the solution ASAP, because I can not move to next step of my application without doing this.


here is the code

try
{
    Cursor.Current = Cursors.WaitCursor;
    var drives = DriveInfo.GetDrives().Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable).ToList();
    cmbDrive.Items.Clear();
    foreach (var dir in drives)
    {
        cmbDrive.Items.Add(dir.Name);                 
    }
}
catch (Exception ex)
{                
    MessageBox.Show(ex.Message);
}
finally
{
    Cursor.Current = Cursors.Default;
}




请帮助我的朋友们....

谢谢
Kapil




Please help me friends....

Thanks
Kapil

推荐答案

大家好,

很高兴告诉您,我已经完成了这项任务.

我将向您提供链接,这些链接使我得以实现:[这些链接真是太棒了]

1) http://usbspeed.nirsoft.net/usb_drive_speed_summary.html

我得到了USB及其VID和PID的列表.然后,我创建了已排序列表的序列化列表.我对序列化列表做了一些更改

2) http://emmet-gray.com/Articles/USB_SerialNumbers.htm

转到页面末尾并获取"USBView.zip".


帮助链接: http://www.linux-usb.org/usb.ids

谢谢
Kapil Waghe
Hello All,

I am very happy to say you that I have done this task.

I am going to provide you the links which helped me to make it possible : [The links are really AWESOME ]

1) http://usbspeed.nirsoft.net/usb_drive_speed_summary.html

I got the list of USB and their VID and PID. Then I created a serialized list of the sorted list. I made some changes into the serialized list

2) http://emmet-gray.com/Articles/USB_SerialNumbers.htm

Go to the end of page and get the "USBView.zip".


Help link : http://www.linux-usb.org/usb.ids

Thanks
Kapil Waghe


您可以通过DeviceInfo的IsReady属性检查设备状态,以检查其是否已连接并准备使用.
但是IMO不能仅获取笔式驱动器,因为其他设备(例如USB HDD)已连接到计算机,因此也会列出.
代码示例:
You can check device status by IsReady property of DeviceInfo for checking whether its attached and ready to use or not.
But IMO you cant fetch only pen drives because other devices like USB HDD is attached to machine than this will also be listed.
Code sample:
DriveInfo[] allDrives = DriveInfo.GetDrives();
            foreach (DriveInfo d in allDrives)
            {

                if (d.IsReady && (d.DriveType == DriveType.Removable ))
                {

                }
            }


这篇关于C#仅获取笔式驱动器列表而不是其他设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆