本文介绍了如何读取硬盘来使用温度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能看到Harrdisk温度somekind的SMART API或类似的东西吗?

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

我只是想临时,闲来无事在C#

i just want the temp, nothing else in C#

推荐答案

下面是代码片段从这个的
希望它能帮助

Here is code snippet from this articleHope it helps

//S.M.A.R.T.  Temperature attritube

const byte TEMPERATURE_ATTRIBUTE = 194;
public List GetDriveTemp()
{
    List retval = new List();
    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;
}

这篇关于如何读取硬盘来使用温度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:09