Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


Edit: here is the code
C#
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;
}



Please help me friends....

Thanks
Kapil
Posted
Updated 8-Sep-11 2:49am
v3
Comments
Suresh Suthar 8-Sep-11 7:12am    
Post your code.
Kapil Waghe 8-Sep-11 7:19am    
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;
}
lukeer 8-Sep-11 8:50am    
Please use "Improve question" to post your code so that it can display syntax-highlighted (already done this time ;-) ).
Kapil Waghe 8-Sep-11 8:56am    
Thanks for your valuable suggestion. I will do remember this.
Kapil Waghe 8-Sep-11 7:26am    
Thank you :)

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
 
Share this answer
 
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:
C#
DriveInfo[] allDrives = DriveInfo.GetDrives();
            foreach (DriveInfo d in allDrives)
            {

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

                }
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900