使用 BAT 和 Python 脚本更改 AAA.bat 中的参数为电源计划 GUID

本文将介绍如何使用 BAT 和 Python 脚本将 AAA.bat 文件中的参数设置为当前电源计划中 Acer 方案的 GUID。

背景

假设你的系统是英文系统,并且你想要将 AAA.bat 文件中的参数 Value 替换为当前电源计划中 Acer 方案的 GUID。

BAT 脚本

@echo off
for /f 'tokens=2 delims=:(' %%a in ('powercfg /list ^| find 'Acer'') do set GUID=%%a
set 'SetValue=Value'
set 'command=D:\STRESSTOOL\StressAutoTest\AutoTool\AAA.bat %SetValue%'
set 'command=%command:Value=%GUID%'
%command%
echo GUID %GUID% has been set as the new parameter for AAA.bat.

Python 脚本

import subprocess

# 获取当前电源计划中 Acer 方案的 GUID
output = subprocess.check_output('powercfg /list | find 'Acer'', shell=True).decode()
GUID = output.split('(')[1].split(')')[0]

# 替换 AAA.bat 中的参数 Value 为 Acer 方案的 GUID
with open('D:\STRESSTOOL\StressAutoTest\AutoTool\AAA.bat', 'r') as f:
    content = f.read()
content = content.replace('Value', GUID)
with open('D:\STRESSTOOL\StressAutoTest\AutoTool\AAA.bat', 'w') as f:
    f.write(content)

print(f'GUID {GUID} has been set as the new parameter for AAA.bat.')

说明

  • BAT 脚本使用 powercfg /list 命令列出所有电源计划,并通过 find 'Acer' 命令查找包含 'Acer' 的方案。然后使用 for 循环提取 GUID 并将其存储在 GUID 变量中。最后,将 GUID 变量替换 AAA.bat 文件中的 Value 参数。
  • Python 脚本使用 subprocess.check_output() 命令执行 powercfg /list 命令,并使用 find 'Acer' 命令查找包含 'Acer' 的方案。然后使用字符串操作提取 GUID 并将其存储在 GUID 变量中。最后,使用 replace() 方法将 AAA.bat 文件中的 Value 参数替换为 GUID

注意

  • 确保你的系统中存在 AAA.bat 文件,并且文件路径正确。
  • 确保你拥有修改 AAA.bat 文件的权限。
  • 可以根据你的需要修改代码中的文件路径和参数名称。

结论

通过使用 BAT 或 Python 脚本,你可以轻松地将 AAA.bat 文件中的参数设置为当前电源计划中 Acer 方案的 GUID。这可以帮助你更好地管理你的电源计划,并提高你的系统性能。

如何使用 BAT 和 Python 脚本更改 AAA.bat 中的参数为电源计划 GUID

原文地址: https://www.cveoy.top/t/topic/nXdx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录