Seth Spearman
Seth Spearman

Reputation: 6780

How to enumerate hard drives

I am writing a .net winforms application. I want to be able to enumerate all of the hard drives on a system.

Furthermore I would love to be able to determine which of the drives is Fixed and Which is removable.

Finally, of the removable drives, I would love to be able to determine which of them is a flash (SSD or thumb) drive versus a standard hard drive.

Upvotes: 0

Views: 1949

Answers (3)

Thomas Levesque
Thomas Levesque

Reputation: 292425

DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
    if (drive.DriveType == DriveType.Fixed)
    {
        // Do something
    }
    else if (drive.DriveType == DriveType.Removable)
    {
        // Do something else
    }
}

But I don't know how you can determine whether it's Flash, SSD or hard drive... maybe with WMI

Upvotes: 1

Anton Gogolev
Anton Gogolev

Reputation: 115741

You can use WMI to do that. You'll need either Win32_DiskDrive or Win32_LogicalDisk.

Upvotes: 1

Ian
Ian

Reputation: 34489

For the first two points you want the following. I think you might have to switch to WMI to determine if a removable drive is solid state or hard drive based.

foreach(DriveInfo info in DriveInfo.GetDrives())
{
   Console.WriteLine(info.Name + ":" + info.DriveType);
}

Produces a list of all the drives and their type from the DriveType Enum

Upvotes: 6

Related Questions