如何从powercfg.exe(批处理)中读取电脑的自动睡眠时间
问题描述:
我有一个批处理文件,可在0分钟后(也就是从不睡眠)自动将计算机设置为睡眠状态。然后,我想重新回到以前的状态。我的问题是,如何在关闭前将当前的睡眠时间设置为变量?提前致谢!如何从powercfg.exe(批处理)中读取电脑的自动睡眠时间
CLARIFICATION:我是新来的批次,所以随时指出一些东西。这是我目前的脚本:
@echo off
tasklist /v | find "Server" > nul
if errorlevel 1 (
title Server
set "time=[WHAT DO I PUT HERE?]" ::Gather current value for "put the computer to sleep:"
C:
cd C:windows\system32\powercfg.exe -change -standby-timeout-ac 0 ::Set the computer's sleep time to 0 (off)
D:
cd D:/Users/Elijah/Desktop/Tekkit_Server_v1.2.9g/ ::Do tasks
java -Xmx12G -Xms10G -jar Tekkit.jar nogui
cd C:windows\system32\powercfg.exe -change -standby-timeout-ac %time% ::When that's done, change the sleep setting back to what it was before we set it to 0
title Server [STOPPED]
pause
) else (::If bad stuff happens
title Server [FAILED]
echo A server is already running
pause
)
我想使用这个脚本的一些自动化与Minecraft服务器。当我从电脑运行服务器时,我必须在控制面板中将“将电脑设置为睡眠”设置更改为0分钟。我已经在脚本中进行了设置,但现在我的问题是重新启用自动睡眠并设置为之前的状态。所以要做到这一点,我想将该值存储在一个名为time
的变量中。我会怎么做?
答
的部分答案:
试用powercfg -list
。这将提供计算机上保存的能量方案列表。复制你需要的模式的ID(如果有多个)。接下来,您想要获得另一个ID:powercfg -aliases
您将获得GUID和其后的文本列表。查找SUB_SLEEP
并复制该ID。
现在运行命令powercfg -q <1stID> <2ndID>
将输出更多的列表,您想在其中寻找类似Sleep after
的东西。在此之下,应该有像Possible Maximum
Possible minimum
这样的值,并且在当前设置的那个块值中进一步低于这个值。
这就是为什么它是一个部分的答案...我不知道如何解析输出。但我相信别人会帮助你:)
我们需要你的批处理代码!所以[编辑你的问题](http://*.com/posts/39606633/edit)并发布! – Hackoo