C# – How to identify system hard drive using Win32_DiskDrive

cwmi

I'm using WMI to get info about hard drives on a computer but I just can't find the property that will allow me to identify which hard drive is used as system drive where Windows is installed.

ManagementObjectSearcher mos_HDD = new ManagementObjectSearcher("select * from Win32_DiskDrive");

I tried iterating through all properties but neither one looks like it holds the info I need.

foreach (ManagementObject mo_HDD in mos_HDD.Get())
{
      Console.WriteLine("HDD Properties:");
      foreach (PropertyData pd in mo_HDD.Properties)
      {
           Console.WriteLine("\tName: {0} \tValue: {1}", pd.Name, pd.Value != null ? pd.Value.ToString() : "NULL");
      }
} 

I've also looked at MSDN documentation but w/o luck.

What I'm trying to do here is to get some kind of identifier for a system drive (such as Signature or Serial number).

Any help to get this info is highly appreciated.

Best Answer

you can get it as :

  public static void Main()
    {
        try
        {
            ManagementObjectSearcher searcher = 
                new ManagementObjectSearcher("root\\CIMV2", 
                "SELECT * FROM Win32_DiskDrive"); 

            foreach (ManagementObject queryObj in searcher.Get())
            {                 
                Console.WriteLine("SerialNumber: {0}", queryObj["SerialNumber"]);
                Console.WriteLine("Signature: {0}", queryObj["Signature"]);
            }
        }
        catch (ManagementException e)
        {

        }
    }