HOW TO LOOKUP HARD DRIVE MODEL WITH C#?

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
C# 
C#
 1779  View(s)
Ratings:
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 "";
    }
  1. Samuel Fernandes

    Post:159

    Points:1117
    Re: How to lookup Hard Drive model with C#?

    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
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!