如何通过 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 -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
— 设置关闭前的时间.使用-t 0
立即关闭.-c
— 添加关闭消息.该消息将最终出现在事件日志中.-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.
- The
-f
option from JosephStyons - Using
rundll32
from VonC - The Run box from Dean
- Remote shutdown from Kip
这篇关于如何通过 bat 文件关闭、重新启动或注销 Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!