Home > DeveloperSection > Forums > How to lookup Hard Drive model with C#?
Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    October-16-2013 8:12 AM

 C# C# 
Ratings:


 1 Reply(s)
 1486  View(s)
Rate this:

I'm trying to get device information about particular local hard drives. I've been able to create a few value returning methods using the DriveInfo class like this:

public string getDriveFormat(string driveName)
    {
        foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
        {
            if (driveInfo.IsReady && driveInfo.Name == driveName)
            {
                return driveInfo.DriveFormat;
            }
        }
        return "";
    }


Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    October-16-2013 8:29 AM

Note: - Add reference of System.management

WqlObjectQuery wqlObjectQuery = new WqlObjectQuery("SELECT * FROM Win32_DiskDrive");
ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(wqlObjectQuery);
foreach (ManagementObject managementObject in managementObjectSearcher.Get()) {
Console.WriteLine("Hard Drive Caption = " + managementObject["Caption"]);
Console.WriteLine("Hard Drive DeviceID = " + managementObject["DeviceID"]);
Console.WriteLine("Hard Drive Decsription = " + managementObject["Description"]);
Console.WriteLine("Hard Drive Manufacturer = " + managementObject["Manufacturer"]);
Console.WriteLine("Hard Drive Media Type = " + managementObject["MediaType"]);
Console.WriteLine("Hard Drive Model = " + managementObject["Model"]);
Console.WriteLine("Hard Drive Name = " + managementObject["Name"]);
}

Not sure if you need to consider mounted drives as well:

foreach(ManagementObject managementObject in new ManagementObjectSearcher("Select * from Win32_Volume" ).Get())
{
  //Code Here
}

Don't want to miss updates? Please click the below button!

Follow MindStick