如何将键盘快捷键链接到 Windows 7 中的不同电源计划/配置文件?

如何将键盘快捷键链接到 Windows 7 中的不同电源计划/配置文件?

例如,我的 Dell e6420 上可用的不同电源计划列示如下: 在此处输入图片描述

我如何通过键盘快捷键链接这些选项,以便我可以 a) 切换它们,或 b) 迭代计划?

答案1

正如我在回答中提到的那样这里,您可以检查GUID为各种计划创建单独的快捷方式(使用键盘快捷键)来Windows\System32\Powercfg.exe激活每个计划(注意目标字段如下):

1

但是,为了让事情变得更容易,您不必查找并仔细复制粘贴所有这些 GUID,我为您准备了几个批处理文件。

第一个,电源计划更改程序,将使您能够仅使用一个数字在系统上的所有可用计划之间快速切换。运行它而不使用参数将打印如下内容:

Usage: PowerPlanAlter [Number]

  1 = "Balanced" [GUID = 381b4222-f694-41f0-9685-ff5bb260df2e]
  2 = "High performance" [GUID = 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c]
  3 = "My Custom Plan 1 (Reduced fan speeds)" [GUID = 938ef152-e95f-4aed-acea-e1c8a0f4493f]
  4 = "My Custom Plan 1 (Increased fan speeds)" [GUID = 9d2a75cb-f035-4376-92db-36fa01e271d2]
  5 = "Power saver" [GUID = a1841308-3541-4fab-bc81-f71556f20b4a]

Current power plan = "Balanced" [GUID = 381b4222-f694-41f0-9685-ff5bb260df2e]

您可以从命令行调用它,也可以创建多个快捷方式,每个计划一个。以下是代码:

@echo off
set pcnt=0
setlocal enableextensions enabledelayedexpansion
for /f "skip=3 tokens=2* delims=:(" %%a in ('powercfg -l') do (
    set /a pcnt+=1
    set tmp=%%b
    if [!tmp:~-1!]==[^)] set tmp=!tmp:~,-1!
    if [!tmp:~-1!]==[*] set tmp=!tmp:~,-3!&& set cp=!pcnt!
    set pname_!pcnt!=!tmp!
    for /f %%c in ("%%a") do set pguid_!pcnt!=%%c
)
echo.
powercfg -s !pguid_%1! 2>NUL
if errorlevel 1 (
    echo Usage: %0 [Number]
    echo.
    for /l %%d in (1,1,!pcnt!) do echo   %%d = "!pname_%%d!" [GUID = !pguid_%%d!]
    echo.
    for /l %%e in (!cp!,1,!cp!) do echo Current power plan = "!pname_%%e!" [GUID = !pguid_%%e!]
) else (
    for /l %%f in (!cp!,1,!cp!) do echo Old power plan = "!pname_%%f!" [GUID = !pguid_%%f!]
    echo.
    echo New power plan = "!pname_%1!" [GUID = !pguid_%1!]
)

第二个,电源计划循环,将使您能够快速循环/迭代系统上所有可用的计划。无需参数;只需为其创建快捷方式,每次运行它时,都会激活下一个计划(循环回到最后一个计划之后的第一个计划)。代码如下:

@echo off
set pcnt=0
setlocal enableextensions enabledelayedexpansion
for /f "skip=3 tokens=2* delims=:(" %%a in ('powercfg -l') do (
    set /a pcnt+=1
    set tmp=%%b
    if [!tmp:~-1!]==[^)] set tmp=!tmp:~,-1!
    if [!tmp:~-1!]==[*] set tmp=!tmp:~,-3!&& set cp=!pcnt!
    set pname_!pcnt!=!tmp!
    for /f %%c in ("%%a") do set pguid_!pcnt!=%%c
)
echo.
set /a np=!cp!%%!pcnt!+1
for /l %%d in (!cp!,1,!cp!) do echo Old power plan = "!pname_%%d!" [GUID = !pguid_%%d!]
echo.
for /l %%e in (!np!,1,!np!) do powercfg -s !pguid_%%e! && echo New power plan = "!pname_%%e!" [GUID = !pguid_%%e!]

如果您通过快捷方式调用这些命令并希望查看输出,只需pause在末尾添加一个命令即可。这些命令在 Windows 7 x64 上运行良好,但如果遇到问题请告诉我。

(哦,如果您不太熟悉批处理文件,只需将代码复制粘贴到记事本中,然后分别保存为“PowerPlanAlter.bat”和“PowerPlanCycle.bat”,引文。)

相关内容