C++ CPU负载和CPU温度的C++代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8032807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:53:43  来源:igfitidea点击:

C++ code for CPU load and CPU temperature

c++loadcpu

提问by Sara

I want to see CPU temperature and CPU load in Windows. I have to write it myself not using software like Core Temp. How can I access this information?

我想在 Windows 中查看 CPU 温度和 CPU 负载。我必须自己编写,而不是使用Core Temp 之类的软件。我怎样才能访问这些信息?

I read a similar question to mine, but there was no useful answer:(.

我读了一个与我类似的问题,但没有有用的答案:(。

采纳答案by Gigamegs

Recently I have started a similar project. I needed to read the cpu temperature and to control the fan in Linux and Windows. I don't know much about C++ and VS and DDK but I figured how to write a simple kernel driver and a simple program with winring0. In my laptop (and most other) the temperature and the fan is controled by the embedded controller. You have 2 choices, either you can write a kernel driver or you can use a library to access the embedded controller. It's because Windows protect the ec from being accessed with normal user rights. A good (and working) library is winring0 (WinRing0_1_3_1b). A useful program to check the ec and everything else in Windows is the RW tool.

最近我开始了一个类似的项目。我需要在 Linux 和 Windows 中读取 CPU 温度并控制风扇。我不太了解 C++、VS 和 DDK,但我想出了如何用 winring0 编写一个简单的内核驱动程序和一个简单的程序。在我的笔记本电脑(和大多数其他)中,温度和风扇由嵌入式控制器控制。您有两种选择,可以编写内核驱动程序,也可以使用库来访问嵌入式控制器。这是因为 Windows 保护 ec 不被普通用户权限访问。winring0 (WinRing0_1_3_1b) 是一个好的(并且可以工作的)库。在 Windows 中检查 ec 和其他所有内容的有用程序是 RW 工具。

回答by tolitius

Take a look at Getting CPU tempfrom MSDN forums, there are a few approaches.

从 MSDN 论坛查看获取 CPU 温度,有几种方法。

As to the sane way, you can use Win32_TemperatureProbeclass, that gets its intel from SMBIOS.

至于sane way,您可以使用Win32_TemperatureProbe类,该类从 SMBIOS 获取其信息。