Friday 6 November 2020

Get CPU and GPU Temp using Python Windows, Without Running as Admin

I was wondering if there was a way to get the CPU and the GPU temperature in python on Windows WITHOUT RUNNING AS ADMIN.

I prefer to only use python modules downloadable with pip, but I am fine with downloading extra things. If your answer requires extra files, I would prefer for it to not require too many files.

I have heard of OpenHardwareMoniter, but this requires me to install something that is not a python module. I would also prefer to not have to run the script as admin to get the results.

When I try doing the below, I get None:

import wmi
w = wmi.WMI()
prin(w.Win32_TemperatureProbe()[0].CurrentReading)

When I try doing the below, I get an error:

import wmi
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print(temperature_info.CurrentTemperature)

Error:

wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147217396, 'OLE error 0x8004100c', None, None)>

I have tried the below code (from question awarded first 50 rep bounty), but it needs to be run as admin:

import clr # the pythonnet module.
clr.AddReference(r'YourdllPath')
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 "/intelcpu/0/temperature" in str(c.Hardware[0].Sensors[a].Identifier):
            print(c.Hardware[0].Sensors[a].get_Value())
            c.Hardware[0].Update()

I am also fine with running windows commands (runnable in cmd) with python, but I have not found one that returns the CPU or GPU temp.

Note: I really do not want to run this as admin.

Added Note: The answer that was awarded the first bounty (50 rep) was given when the question focused on getting a way to get the temperature. I have edited the question to ask how to do this without admin privileges.



from Get CPU and GPU Temp using Python Windows, Without Running as Admin

No comments:

Post a Comment