如何阅读HardDisk温度?

时间:2011-11-10 12:12:32

标签: c# hardware-interface

是否可以使用某种S.M.A.R.T API或类似的东西来查看硬盘温度?

我只想要临时,没有别的C#

2 个答案:

答案 0 :(得分:8)

以下是此article的代码段 希望它有所帮助

//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;
}

答案 1 :(得分:1)

使用VMI和MSStorageDriver_ATAPISmartData获取VendorSpecific字节数组,115字节数是温度。为什么115?更多here

使用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();
    }
 }