views:

382

answers:

2

Hey,

I want to retrieve the list of fixed disks in a system. But C#s GetDrives Fixed Drives are including plug USB Harddisks.

Any idea how I may detect that a fixed Drive is not an USB harddisk or vica versa?

Ciao Ephraim

+2  A: 

use DriveType to detect the type of the drive:

using System.IO;

DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
  if (d.IsReady && d.DriveType == DriveType.Fixed)
  {
    // This is the drive you want...
  }
}

DriveInfo Class

EDIT1:

check the following link: How do I detected whether a hard drive is connected via USB?

Wael Dalloul
But DriveType.Removable are just USB Sticks not USB Harddisks.From Docu: The drive is a removable storage device, such as a floppy disk drive or a USB flash drive.
Ephraim
USB Harddisks are of Type Fixed exactly that is the Problem!
Ephraim
+1  A: 

Solution nicked from http://stackoverflow.com/questions/450009/how-to-get-serial-number-of-usb-stick-in-c :

 //import the System.Management namespace at the top in your "using" statement.
 ManagementObjectSearch theSearcher = new ManagementObjectSearcher(
      "SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'");
MSalters
Correct, though this will list Sticks and Drives, and a quick look through the properties didn't reveal an easy way to find the Drive letter.
Henk Holterman
Apparently ephraim already has those. This solution was intended to show how you'd filter out USB drives. That's why the query was written as `InterfaceType='USB'`, and why it doesn't matter that sticks are included.
MSalters