【问题标题】:Get CPU Temperature using Open Hardware Monitor使用 Open Hardware Monitor 获取 CPU 温度
【发布时间】:2015-02-02 11:32:57
【问题描述】:

我正在尝试使用 OpenHardwareMonitorLib DLL 来获取我的 CPU \ 内核的温度,但是这不会为我返回温度。

我环顾四周,发现这几乎无处不在,但我无法让它发挥作用。

如果有人能告诉我哪里出了问题,我将不胜感激。

这是我的代码:

using System;
using System.Linq;
using System.Management;
using OpenHardwareMonitor.Collections;
using OpenHardwareMonitor.Hardware;
using OxyPlot;
using OxyPlot.Series;


namespace cs_TempReader
{
    class Program
    {
        private DateTime now;
        protected readonly ListSet<ISensor> active = new ListSet<ISensor>();
        public event SensorEventHandler SensorAdded;
        public event SensorEventHandler SensorRemoved;

        protected virtual void ActivateSensor(ISensor sensor)
        {
            if (active.Add(sensor))
                if (SensorAdded != null)
                    SensorAdded(sensor);
        }

        private static void Main(string[] args)
        {
            var myComputer = new Computer();

            myComputer.CPUEnabled = true;
            myComputer.ToCode();
            myComputer.Open();

            foreach (var hardwareItem in myComputer.Hardware)
            {
                hardwareItem.Update();
                hardwareItem.GetReport();

                Console.WriteLine(hardwareItem.GetReport());

                var series = new LineSeries();

                foreach (var sensor in hardwareItem.Sensors)
                {
                    if (sensor.SensorType == SensorType.Temperature)
                    {
                        Console.WriteLine("{0} {1} {2} = {3}", sensor.Name, sensor.Hardware, sensor.SensorType, sensor.Value);

                    }

                }
            }
        }
    }
}

我的最终目标是能够将其绑定到更大的应用程序中。

【问题讨论】:

  • OHM 应用程序是否正常工作?
  • 查看其他一些 OpenHardwareMonitor 标记的问题,我遇到了Recent OpenHardwareMonitor Sample Code C#,其中一个答案表明,由于 API 调用的性质,您需要以管理员权限运行 VS。跨度>
  • @Simon:编辑从问题中删除您的签名是正确的,因为您的用户名会自动显示在问题的右下方。
  • 谢谢!如果我刚刚这样做的话,我本可以在昨天完成这个......我想这将进入的应用程序也需要提升权限。
  • 我只是要从这项工作的纯粹新颖性中赞成这一点。听起来很酷!

标签: c# openhardwaremonitor


【解决方案1】:

您需要在应用程序中请求更高的执行级别,以便此代码能够正常工作。

为此,您必须:

  • 右键单击项目;
  • 点击添加
  • 点击新建项目...
  • 在搜索栏上输入 ma​​nifest
  • 点击确定

之后,您必须更改清单上的这一行:

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

到这里:

<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

【讨论】:

    【解决方案2】:

    可能你必须强制你的应用程序以管理员身份运行,然后你的代码才能工作。

    右键单击项目>添加新项目,选择“应用程序清单文件”。

    改变

    <requestedExecutionLevel>
    

    元素到:

    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    

    教程在这里,你可以看看。

    http://www.lattepanda.com/topic-f11t3004.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 2022-08-05
      相关资源
      最近更新 更多