如何从powercfg.exe中读取PC的自动睡眠时间(批处理) [英] How to READ the auto sleep time of pc from powercfg.exe (batch)

查看:261
本文介绍了如何从powercfg.exe中读取PC的自动睡眠时间(批处理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件,该文件会自动将计算机设置为在0分钟后进入睡眠状态(也就是从不进入睡眠状态).然后,我想将其设置回之前的状态.我的问题是如何在关闭它之前将当前的睡眠时间设置为一个变量?预先感谢!

I have a batch file that automatically sets the computer to sleep after 0 minutes (aka never sleep). Then I want to set it back to what it was before. My question is how would I set the current sleep time to a variable before I turn it off? Thanks in advance!

澄清:我是新来的一批,请随时指出一些东西.这是我当前的脚本:

CLARIFICATION: I'm new to batch so feel free to point stuff out. Here's my current script:

@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的变量中.我该怎么办?

I want to use this script for some automation with a Minecraft server. When I run a server from my computer, I have to change the "put the computer to sleep" setting to 0 minutes in control panel. I have already set this up in the script, but now my problem is turning auto-sleep back on and setting to what it was before. So to do that I want to store the value in a variable called time. How would I do that?

推荐答案

部分答案:

尝试powercfg -list.这将提供保存在计算机上的能源方案的列表.复制所需模式的ID(如果有多个).接下来,您要获得另一个ID:powercfg -aliases您将获得一个GUID列表以及它们后面的文本.查找SUB_SLEEP并复制该ID.
现在,运行命令powercfg -q <1stID> <2ndID>将输出更多列表,您希望在其中查找类似Sleep after的内容.低于该值的地方应为Possible Maximum Possible minimum之类的值,并进一步低于该值的当前设置的块值.

Try out powercfg -list. This will provide a list of the energy-schemes that are saved on your computer. Copy the ID of the mode you need (if there is more than one). Next you want to get another ID: powercfg -aliases You will get a list of GUID's and text behind them. Look for SUB_SLEEP and copy that ID as well.
Now running the command powercfg -q <1stID> <2ndID> will output more lists where you want to look for something like Sleep after. Below that there should be values like Possible Maximum Possible minimum and further below in that block values for the current setting.

这就是为什么它是部分答案的原因...我不知道如何解析输出.但我确信会有其他人帮助您:)

This is why it is a partial answer... I have no idea how to parse the output. But I am sure that someone else will help you with that :)

这篇关于如何从powercfg.exe中读取PC的自动睡眠时间(批处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆