Skip to content

Instantly share code, notes, and snippets.

@chand1012
Created February 20, 2018 18:19
Show Gist options
  • Save chand1012/1ae6f3703089526b3ac9148e8f79dccb to your computer and use it in GitHub Desktop.
Save chand1012/1ae6f3703089526b3ac9148e8f79dccb to your computer and use it in GitHub Desktop.
Get CPU and GPU temps from Windows with Python and OHM
import wmi
def avg(value_list):
num = 0
length = len(value_list)
for val in value_list:
num += val
return num/length
w = wmi.WMI(namespace="root\\OpenHardwareMonitor")
sensors = w.Sensor()
cpu_temps = []
gpu_temp = 0
for sensor in sensors:
if sensor.SensorType==u'Temperature' and not 'GPU' in sensor.Name:
cpu_temps += [float(sensor.Value)]
elif sensor.SensorType==u'Temperature' and 'GPU' in sensor.Name:
gpu_temp = sensor.Value
print "Avg CPU: {}".format(avg(cpu_temps))
print "GPU: {}".format(gpu_temp)
@kshitij1235
Copy link

i got to have this error

$ python -u "d:\kshitij\python\overlay\cpu_temp.py"
Traceback (most recent call last):
File "D:\programs\python\python3.10\lib\site-packages\wmi.py", line 1340, in connect
obj = GetObject(moniker)
File "D:\programs\python\python3.10\lib\site-packages\win32com\client_init_.py", line 85, in GetObject
return Moniker(Pathname, clsctx)
File "D:\programs\python\python3.10\lib\site-packages\win32com\client_init_.py", line 102, in Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
pywintypes.com_error: (-2147217394, 'OLE error 0x8004100e', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:\kshitij\python\overlay\cpu_temp.py", line 11, in
w = wmi.WMI(namespace="root\OpenHardwareMonitor")
File "D:\programs\python\python3.10\lib\site-packages\wmi.py", line 1354, in connect
handle_com_error()
File "D:\programs\python\python3.10\lib\site-packages\wmi.py", line 258, in handle_com_error
raise klass(com_error=err)
wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147217394, 'OLE error 0x8004100e', None, None)>

@kevinjonson133
Copy link

i got the same error:
wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147217394, 'OLE error 0x8004100e', None, None)>

@Mike-Kuznetsov
Copy link

Same error <x_wmi: Unexpected COM Error (-2147217394, 'OLE error 0x8004100e', None, None)>

@wfxey
Copy link

wfxey commented May 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment