Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase access to administrator permissions #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions host_python/windows_host.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"

start python windows_host.py
38 changes: 26 additions & 12 deletions host_python/windows_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
# Make sure 'OpenHardwareMonitorLib.dll' is in the same folder as this Python script!
#
# Change your COM port to match that of your COM port!

from __future__ import print_function
import serial
import os
import time
import clr
import psutil
import ctypes, sys

updateTime = 4 #number of seconds between each update

Expand All @@ -28,7 +29,7 @@

def sendData(temp, rpm, gpu, free_disk, free_mem, procs):
try:
connection = serial.Serial('COM16') # Change this to match your COM port!
connection = serial.Serial('COM35') # Change this to match your COM port!
data = temp + ',' + rpm + ',' + str(free_mem) + ',' + str(free_disk) + ',' + gpu + ',' + str(procs) + '/'
connection.write(data.encode())
print("Data written", data.encode())
Expand Down Expand Up @@ -76,14 +77,27 @@ def parse_sensor(sensor):

HardwareHandle = initialize_openhardwaremonitor()

while(1):
fetch_stats(HardwareHandle)
obj_Disk = psutil.disk_usage('c:\\') # Drive letter with double \\
free_disk = int(obj_Disk.free / (1024.0 ** 3))
free_mem = (int((psutil.virtual_memory().total - psutil.virtual_memory().used)/ (1024 * 1024)))
proc_counter = 0
for proc in psutil.process_iter():
proc_counter += 1
sendData(cpu_temp, rpm, gpu_temp, free_disk, free_mem, proc_counter)
time.sleep(updateTime)
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False

if is_admin():
# 将要运行的代码加到这里
while(1):
fetch_stats(HardwareHandle)
obj_Disk = psutil.disk_usage('c:\\') # Drive letter with double \\
free_disk = int(obj_Disk.free / (1024.0 ** 3))
free_mem = (int((psutil.virtual_memory().total - psutil.virtual_memory().used)/ (1024 * 1024)))
proc_counter = 0
for proc in psutil.process_iter():
proc_counter += 1
sendData(cpu_temp, rpm, gpu_temp, free_disk, free_mem, proc_counter)
time.sleep(updateTime)
else:
if sys.version_info[0] == 3:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
else:#in python2.x
ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)