windows 如何制作休眠批处理文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7977743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make a hibernation batch file?
提问by ryanscottmurphy
I'm trying to make a batch file that executes a simple command:
我正在尝试制作一个执行简单命令的批处理文件:
shutdown -h
I've created a shutdown.bat
file with that exact line in it, yet when I run it, all it does is spam the command prompt like crazy.
我已经创建了一个shutdown.bat
包含该行的文件,但是当我运行它时,它所做的只是疯狂地向命令提示符发送垃圾邮件。
I've looked at batch file sites, @echo off
seems popular, but doesn't that just hide output while the commands are executed just the same?
我看过批处理文件站点,@echo off
似乎很流行,但是在执行相同命令时,这不只是隐藏输出吗?
回答by ryanscottmurphy
It turns out that adding a change directory command to the root of the drive fixes the problem. The final text that I ended up using in the .bat file was:
事实证明,向驱动器的根目录添加更改目录命令可以解决此问题。我最终在 .bat 文件中使用的最终文本是:
cd c:\
shutdown /h
回答by LJ Neveral
I believe I am very late for this but just in case someone else comes across this.
The issue was indeed with the name of the bat file. You were calling shutdown -h
and the bat file was called shutdown.bat
hence the bat file was calling itself causing the loop of the command prompts. To fix this you either rename the bat file or specify the directory where shutdown
is located.
我相信我已经很晚了,但以防万一其他人遇到这个问题。问题确实出在 bat 文件的名称上。您正在调用shutdown -h
并且调用了 bat 文件,shutdown.bat
因此 bat 文件正在调用自身,导致命令提示符循环。要解决此问题,您可以重命名 bat 文件或指定所在的目录shutdown
。
回答by Teun Pronk
Would love to say I figured this out but I simply googled it. The code you need is
很想说我想通了,但我只是在谷歌上搜索了它。你需要的代码是
%windir%System32rundll32.exe powrprof.dll,SetSuspendState
If you go to start -> run and then type this in it should work. So if you have hibernate enabled in the poweroptions this should also work in a batch file.
如果你去开始 -> 运行然后输入它应该可以工作。因此,如果您在 poweroptions 中启用了休眠,这也应该在批处理文件中工作。
Hope this helped you
希望这对你有帮助
Edit: P.s. click the white little V under the arrows (left of this answer) to accept the answer ;)
编辑:Ps 单击箭头下方的白色小 V(此答案左侧)以接受答案;)
回答by Rashid Qazizada
For shutdown:
对于关机:
c:\windows\system32\shutdown -s -f -t 00
(or do ...shutdown -p -f
).
(或做...shutdown -p -f
)。
E.g.: set the time -t 1000
and save and run it.
例如:设置时间-t 1000
并保存并运行它。
To abort just c:\windows\system32\shutdown -a
in different batch file.
仅c:\windows\system32\shutdown -a
在不同的批处理文件中中止。
Very important point to note: if you locate this batch file in your startup then it will execute the s/h/r
immediately. E.g. you create a logoff batch file and you locate it in startup
it will logoff the pc within the given time/immediately. However, when you hold shift when logging then it will abort the logoff batch file otherwise you pc will logoff again and again. You don't have to do this I am not sure if it works on every PC.
非常重要的一点要注意:如果您在启动时找到此批处理文件,它将s/h/r
立即执行。例如,您创建一个注销批处理文件并在启动时找到它,它将在给定的时间内/立即注销 PC。但是,当您在登录时按住 shift 时,它将中止注销批处理文件,否则您的电脑将一次又一次地注销。您不必这样做,我不确定它是否适用于每台 PC。
Create a user and try it there in case you could not log in. good luck
创建一个用户并在那里尝试,以防您无法登录。祝您好运
For restart:
重启:
c:\windows\system32\shutdown -r -t 00
For hibernate:
对于休眠:
c:\windows\system32\shutdown /h
Reference: https://www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/
参考:https: //www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/