我正在尝试创建一个 python 脚本来自动更改 MSI Afterburner 中的配置文件,但我遇到了
PermissionError: [WinError 5] Access is denied
错误。我试图看看它是否是路径/权限问题,但不是。我什至尝试在系统环境变量中添加 MSI Afterburner 路径,但没有任何效果。
import subprocess
import time
# Function to switch profiles
def switch_profile(current_profile):
if current_profile == "1":
new_profile = "2"
else:
new_profile = "1"
subprocess.run([afterburner_path, f"-Profile{new_profile}"])
# Add a delay to allow Afterburner to switch profiles
time.sleep(1)
# Path to MSI Afterburner executable
afterburner_path = '"C:/Program Files (x86)/MSI Afterburner/MSIAfterburner.exe"'
# Function to get the current profile
def get_current_profile():
result = subprocess.run([afterburner_path, "-Profile"], capture_output=True, text=True)
output_lines = result.stdout.strip().split("\n")
current_profile = output_lines[-1].split(":")[-1].strip()
return current_profile
# Switch profiles
current_profile = get_current_profile()
switch_profile(current_profile)
这是我收到的错误:
File "c:\Users\iwanh\Desktop\Leetcode\msi-afterburner.py", line 25, in <module>
current_profile = get_current_profile()
File "c:\Users\iwanh\Desktop\Leetcode\msi-afterburner.py", line 19, in get_current_profile
result = subprocess.run([afterburner_path, "-Profile"], capture_output=True, text=True)
File "C:\Users\iwanh\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 503, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\iwanh\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\iwanh\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1440, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
您的脚本需要以管理员身份运行才能正常运行。