我正在尝试使用OpenHardwareMonitor来阅读有关硬件诊断的信息.如果您曾经尝试过使用OHM,那么您知道关于它的文档很少,据我所知,没有其他开源库具有如此精确和强大的功能.
我已经能够从CPU获得负载和时钟速度,但无法获得温度.
我也没有收到有关硬盘的任何信息(温度是我最担心的问题).
这是我的实现,它应该返回它拥有的所有内容,但是到目前为止,我仅获得有关RAM(无温度),CPU(无温度)和GPU的有限信息.
CPU温度是我要跟踪的最重要的统计信息.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using OpenHardwareMonitor.Hardware;
namespace OHMWrapper
{
public class MySettings : ISettings
{
private IDictionary<string, string> settings = new Dictionary<string, string>();
public MySettings(IDictionary<string, string> settings)
{
this.settings = settings;
}
public bool Contains(string name)
{
return settings.ContainsKey(name);
}
public string GetValue(string name, string value)
{
string result;
if (settings.TryGetValue(name, out result))
return result;
else
return value;
}
public void Remove(string name)
{
settings.Remove(name);
}
public void SetValue(string name, string value)
{
settings[name] = value;
}
}
public class OHW
{
private static OHW m_Instance;
public static OHW Instance
{
get
{
if (m_Instance == null)
m_Instance = new OHW();
return m_Instance;
}
}
private OHW()
{
m_Instance = this;
}
public void GetCPUTemp()
{
MySettings settings = new MySettings(new Dictionary<string, string>
{
{ "/intelcpu/0/temperature/0/values", "H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Iu6//MH37x79i9/+NX6N3/TJm9/5f/01fw1+fosnv+A/+OlfS37/jZ/s/Lpv9fff6Ml/NTef/yZPnozc5679b+i193//TQZ+/w2Dd+P9/sZeX/67v/GTf/b3iP3u4/ObBL//73+i+f039+D8Zk/+xz/e/P6beu2TQZju8yH8f6OgzcvPv/U3/Rb8+z/0f/9b/+yfaOn8079X6fr6Cws7ln/iHzNwflPv99/wyS/+xY4+v/evcJ+733+jJ5//Cw7/4ndy9Im3+U2e/Fbnrk31C93vrt/fyPvdb+N//hsF7/4/AQAA//9NLZZ8WAIAAA==" },
{ "/intelcpu/0/load/0/values", "H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Iu6//MH37x79i9++mpwcv/md/9df89egZ/xX/ym/5y/4D37618Lv7ya//u+58+u+5d9/z7/5t/w9/6u5fP5bH/6av+eTkXyefXxp26ONaf/v/dG/sf39D/rvnv4e5vc/0IP56/waK/vuHzf5I38P8/tv+mv8Rbb9f0pwTF9/zr/1X9vP/8I//+/6Pf7Z30N+/zdf/HX29zd/859q4aCNP5b//U+U3/+7f+zXOjZwfqvDX/V7/o9/vPz+a1G/pv0f+fGlhfk7eZ//N3/0v28//5X0u/n8Cxq7+f1X/tHft20A5x8a/W5/02+BP36Nf+j/nv8XfzrT+c2//Ob4p3+vktvUhNs/+xcWikP6e/4T/5jS5M8/sL8vP/5ff49f/Ivl9//sHzv6PX/vXyG//9R/94/9HuZ34P/5vyC//3W/5e/1exa/k+Bw4bUBnU2bP4Xg/1bn0uafeTH6PatfKL//N3/0t2y/gG9+/8+IzqYNxmU+/+jwX7afY67/nwAAAP//GYSA31gCAAA=" },
});
Computer myComputer = new Computer(settings)
{
MainboardEnabled = true,
CPUEnabled = true,
RAMEnabled = true,
GPUEnabled = true,
FanControllerEnabled = true,
HDDEnabled = true
};
myComputer.Open();
foreach (var hardwareItem in myComputer.Hardware)
{
hardwareItem.Update();
if (hardwareItem.SubHardware.Length > 0)
{
foreach (IHardware subHardware in hardwareItem.SubHardware)
{
subHardware.Update();
foreach (var sensor in subHardware.Sensors)
{
Console.WriteLine(String.Format("{0} {1} = {2}", sensor.Name, sensor.Hardware, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value"));
}
}
}
else
{
foreach (var sensor in hardwareItem.Sensors)
{
Console.WriteLine(String.Format("{0} {1} = {2}", sensor.Identifier, sensor.Hardware, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value"));
}
}
}
}
}
}
我一直在查看源代码,因为它是获取任何信息的唯一方法.这是一个缓慢的过程,但我非常感谢您的帮助.
OpenHardwareMonitor源代码:http://code.google.com/p/open-hardware-monitor/source/browse/
解决方法:
我必须在具有管理权限的情况下运行此代码,才能获取所需的所有信息.我添加了一个清单文件,该文件要求代码与这些文件一起运行.感谢您提供的所有有用信息.