获取电脑CPU温度及CPU使用等信息

代码

import clr   # 安装时使用pip install pythonnet

clr.AddReference(r'E:\PythonCode\RWInfluxDBTest\OpenHardwareMonitor\OpenHardwareMonitorLib')
# e.g. clr.AddReference(r'OpenHardwareMonitor/OpenHardwareMonitorLib'), without .dll
# 修改成OpenHardwareMonitorLib.dll文件的实际路径。
from OpenHardwareMonitor.Hardware import Computer

c = Computer()
c.CPUEnabled = True     # get the Info about CPU
c.GPUEnabled = True     # get the Info about GPU
c.Open()
while True:
    for a in range(0, len(c.Hardware[0].Sensors)):
        # print(c.Hardware[0].Sensors[a].Identifier)
        if "/temperature" in str(c.Hardware[0].Sensors[a].Identifier):
            print(c.Hardware[0].Sensors[a].get_Value())
            c.Hardware[0].Update()

参考:
https://blog.csdn.net/zhaoyi40233/article/details/135088005
温度监测dll文件下载地址: https://openhardwaremonitor.org/
https://blog.csdn.net/m0_37816922/article/details/131455323

posted @ 2025-01-07 16:34  星空28  阅读(62)  评论(0)    收藏  举报