14

Is it possible to see the Harrdisk temperature with somekind of S.M.A.R.T API or anything like that?

i just want the temp, nothing else in C#

Tipx
  • 7,367
  • 4
  • 37
  • 59
MMM
  • 311
  • 5
  • 14
  • 30
  • 1
    there isen't any problem.. i just need to find a S.M.A.R.T API - ive google'd but coulden't find any.. – MMM Nov 10 '11 at 12:34

2 Answers2

9

Here is code snippet from this article Hope it helps

//S.M.A.R.T.  Temperature attribute
const byte TEMPERATURE_ATTRIBUTE = 194;

public List<byte> GetDriveTemp()
{
    var retval = new List<byte>();
    try
    {
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData");
        //loop through all the hard disks
        foreach (ManagementObject queryObj in searcher.Get())
        {
            byte[] arrVendorSpecific = (byte[])queryObj.GetPropertyValue("VendorSpecific");
            //Find the temperature attribute
            int tempIndex = Array.IndexOf(arrVendorSpecific, TEMPERATURE_ATTRIBUTE);
            retval.Add(arrVendorSpecific[tempIndex + 5]);
        }
    }
    catch (ManagementException err)
    {
        Console.WriteLine("An error occurred while querying for WMI data: " + err.Message);
    }
    return retval;
}
dbc
  • 104,963
  • 20
  • 228
  • 340
Stecya
  • 22,896
  • 10
  • 72
  • 102
  • why is it tempIndex + 5, and i've posted a question about it already but do you know how to get the data from attribute 193 (load/unload cycle count) – Lyuben Todorov Mar 24 '12 at 15:57
  • 1
    Works fine, once you change `List` to `List`and include the reference to `System.Management`. Returns Celsius for local drives, 0 for a SSD. – TaW Aug 11 '14 at 09:53
2

use VMI and MSStorageDriver_ATAPISmartData to get VendorSpecific byte array and 115 byte number is temperature. Why 115? More here.

Code partly generated with VMI Code Creator

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI",
"SELECT * FROM MSStorageDriver_ATAPISmartData");

foreach (ManagementObject queryObj in searcher.Get())
{
   if (queryObj["VendorSpecific"] != null)
   {
       byte[] arrVendorSpecific = (byte[])(queryObj["VendorSpecific"]);
       string temp = arrVendorSpecific[115].ToString();
    }
 }
Renatas M.
  • 11,694
  • 1
  • 43
  • 62