如何通过bat文件关闭,重新启动或注销Windows? [英] How do I shutdown, restart, or log off Windows via a bat file?
问题描述
我一直在使用远程桌面连接进入工作站.但是在这种环境下,我无法使用开始"菜单中的电源选项.我需要另一种方法来关闭或重新启动.
I've been using Remote Desktop Connection to get into a workstation. But in this environment, I cannot use the power options in Start Menu. I need an alternative way to shutdown or restart.
如何通过命令行控制计算机的电源状态?
How do I control my computer's power state through the command line?
推荐答案
使用 shutdown
命令是:
The most common ways to use the shutdown
command are:
-
shutdown -s
—关闭. -
shutdown -r
—重新启动. -
shutdown -l
-注销. -
shutdown -h
-休眠.
shutdown -s
— Shuts down.shutdown -r
— Restarts.shutdown -l
— Logs off.shutdown -h
— Hibernates.
注意:有一个常见的陷阱,用户认为-h
表示帮助"(它对所有其他命令行程序都起作用...除了shutdown.exe
之外,在其他情况下,它表示休眠").然后,他们运行shutdown -h
并意外关闭了计算机.提防这一点.
Note: There is a common pitfall wherein users think -h
means "help" (which it does for every other command-line program... except shutdown.exe
, where it means "hibernate"). They then run shutdown -h
and accidentally turn off their computers. Watch out for that.
shutdown -i
-交互模式".它不执行任何操作,而是显示一个GUI对话框.
shutdown -i
— "Interactive mode". Instead of performing an action, it displays a GUI dialog.
以上命令可以与以下其他选项结合使用:
The commands above can be combined with these additional options:
-
-f
—强制程序退出.防止关闭过程陷入困境. -
-t <seconds>
—设置关闭前的时间.使用-t 0
立即关闭. -
-c <message>
-添加关闭消息.该消息将最终显示在事件日志中. -
-y
—对所有关机查询强制回答是".
-f
— Forces programs to exit. Prevents the shutdown process from getting stuck.-t <seconds>
— Sets the time until shutdown. Use-t 0
to shutdown immediately.-c <message>
— Adds a shutdown message. The message will end up in the Event Log.-y
— Forces a "yes" answer to all shutdown queries.
注意:任何正式文档中都没有记录此选项.它是由这些StackOverflow用户发现的.
Note: This option is not documented in any official documentation. It was discovered by these StackOverflow users.
我想确保在此答案中也提及其他一些非常好的答案.在这里,它们没有特定的顺序.
I want to make sure some other really good answers are also mentioned along with this one. Here they are in no particular order.
-
-f
选项来自 JosephStyons - 使用
rundll32
VonC - 运行"框 a href ="https://stackoverflow.com/users/14966/dean">教务长
- 远程关闭 基普
- The
-f
option from JosephStyons - Using
rundll32
from VonC - The Run box from Dean
- Remote shutdown from Kip
这篇关于如何通过bat文件关闭,重新启动或注销Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!