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?
The most common ways to use the shutdown command are:
shutdown -s — Shuts down.
shutdown -r — Restarts.
shutdown -l — Logs off.
shutdown -h — Hibernates.
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 — "Interactive mode". Instead of performing an action, it displays a GUI dialog.
shutdown -a — Aborts a previous shutdown command.
The commands above can be combined with these additional options:
-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.
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.
If you are on a remote machine, you may also want to add the -f option to force the reboot. Otherwise your session may close and a stubborn app can hang the system.
I use this whenever I want to force an immediate reboot:
shutdown -t 0 -r -f
For a more friendly "give them some time" option, you can use this:
shutdown -t 30 -r
As you can see in the comments, the -f is implied by the timeout.
Don't use rundll32.exe for this purpose. It expects that the function you passed on the command line has a very specific method signature - it doesn't match the method signature of ExitWindows.
The function signature required for functions called by rundll32.exe is:
void CALLBACK ExitWindowsEx(HWND hwnd, HINSTANCE hinst,
LPSTR pszCmdLine, int nCmdShow);
That hasn't stopped people from using rundll32 to call random functions that weren't designed to be called by rundll32, like user32 LockWorkStation or user32 ExitWindowsEx.
(oops)
The actual function signature for ExitWindowsEx is:
Rundll32 is a leftover from Windows 95, and it has been deprecated since at least Windows Vista because it violates a lot of modern engineering guidelines.
Another small tip: when going the batch file route, I like to be able to abort it in case I run it accidentally. So the batch file invokes the shutdown but leaves you at the command prompt afterwards.
@echo off
echo Shutting down in 10 seconds. Please type "shutdown /a" to abort.
cmd.exe /K shutdown /f /t 10 /r
您可能已经意识到这一点,但以防万一:只需在“运行”框中输入 shutdown -r(或任何您喜欢的命令)并按 Enter 键会更容易。
避免将批处理文件散落在各处。
You're probably aware of this, but just in case: it's much easier to just type shutdown -r (or whatever command you like) into the "Run" box and hit enter.
Saves leaving batch files lying around everywhere.
当远程连接到计算机时(无论如何,目标是 Windows XP;我不确定目标 Windows Vista),尽管开始菜单上的“关闭”被替换为“断开会话”或类似的东西,应该有一个名为“Windows Security”的东西,它也可以做与 Ctrl + Alt + End 相同的事情,如所指出的欧文.
When remoted into a machine (target is Windows XP anyway; I am not sure about target Windows Vista), although Shutdown on the start menu is replaced by Disconnect Session or something like that, there should be one called 'Windows Security' which also does the same thing as Ctrl + Alt + End as pointed to by Owen.
I'm late to the party, but did not see this answer yet.
When you don't want to use a batch file or type the command. You can just set focus to the desktop and then use Alt + F4.
Windows will ask you what you want to do, select shutdown or restart.
发布评论
评论(10)
使用
shutdown
命令的最常见方法是:shutdown -s
— 关闭。shutdown -r
— 重新启动。shutdown -l
— 注销。shutdown -h
— 休眠。注意:有一个常见的陷阱,即用户认为
-h
表示“帮助”(它对所有其他命令行程序都是如此......除了>shutdown.exe
,它的意思是“休眠”)。 然后,他们运行shutdown -h
并意外关闭了计算机。 请注意这一点。shutdown -i
—“交互模式”。 它不执行操作,而是显示 GUI 对话框。shutdown -a
— 中止之前的关闭命令。上面的命令可以与以下附加选项结合使用:
-f
— 强制程序退出。 防止关闭过程卡住。-t
— 设置关机前的时间。 使用-t 0
立即关闭。-c
— 添加关闭消息。 该消息最终将出现在事件日志中。-y
— 强制对所有关闭查询回答“是”。注意:此选项未记录在任何官方文档中。 它是由这些 StackOverflow 用户发现的。
我想确保除了这个答案之外还提到了其他一些非常好的答案。 在这里,它们没有特定的顺序。
-f
选项< /a> 来自 JosephStyonsThe most common ways to use the
shutdown
command are:shutdown -s
— Shuts down.shutdown -r
— Restarts.shutdown -l
— Logs off.shutdown -h
— Hibernates.Note: There is a common pitfall wherein users think
-h
means "help" (which it does for every other command-line program... exceptshutdown.exe
, where it means "hibernate"). They then runshutdown -h
and accidentally turn off their computers. Watch out for that.shutdown -i
— "Interactive mode". Instead of performing an action, it displays a GUI dialog.shutdown -a
— Aborts a previous shutdown command.The commands above can be combined with these additional options:
-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.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
option from JosephStyonsrundll32
from VonC如果您在远程计算机上,您可能还需要添加 -f 选项来强制重新启动。 否则,您的会话可能会关闭,并且顽固的应用程序可能会挂起系统。
每当我想强制立即重新启动时,我都会使用此选项:
对于更友好的“给他们一些时间”选项,您可以使用此选项:
正如您在注释中看到的, -f 是由超时暗示的。
Brutus 2006 是一个为这些选项提供 GUI 的实用程序。
If you are on a remote machine, you may also want to add the -f option to force the reboot. Otherwise your session may close and a stubborn app can hang the system.
I use this whenever I want to force an immediate reboot:
For a more friendly "give them some time" option, you can use this:
As you can see in the comments, the -f is implied by the timeout.
Brutus 2006 is a utility that provides a GUI for these options.
没有人提到用于远程关闭的
-m
选项:另外:
-r
参数会导致重新启动(这通常是您在远程计算机上想要的,因为物理启动它)可能很难)。-f
参数选项强制重新启动。No one has mentioned
-m
option for remote shutdown:Also:
-r
parameter causes a reboot (which is usually what you want on a remote machine, since physically starting it might be difficult).-f
parameter option forces the reboot.原始答案:2008 年 10 月
您还获得了所有
"系列:(rundll32.exe shell32.dll
"请参阅下面的更新)
rundll32.exe user.exe,**ExitWindows**
[快速关闭 Windows]rundll32.exe user.exe,**ExitWindowsExec**
[重新启动 Windows]其中
n
代表:LOGOFF< /code>
SHUTDOWN
REBOOT
FORCE
POWEROFF
(可以组合 -> 6 = 2+4
强制重启
)2015 年 4 月更新(6 年多后):
1800 信息< /a> 请指出评论:
Raymond CHEN 写道:
(哎呀)
并使其清晰可见:
Original answer: Oct. 2008
You also got all the
"serie:rundll32.exe shell32.dll
"(see update below)
rundll32.exe user.exe,**ExitWindows**
[Fast Shutdown of Windows]rundll32.exe user.exe,**ExitWindowsExec**
[Restart Windows]where
n
stands for:LOGOFF
SHUTDOWN
REBOOT
FORCE
POWEROFF
(can be combined -> 6 = 2+4
FORCE REBOOT
)Update April 2015 (6+ years later):
1800 INFORMATION kindly points out in the comments:
Raymond CHEN wrote:
(oops)
And to make it crystal-clear:
另一个小提示:当使用批处理文件路径时,我希望能够中止它,以防我意外运行它。 因此,批处理文件会调用关闭,但随后会将您留在命令提示符处。
另外,由于它是有计时器的,所以你会得到与狩猎时相同的刺激感在俄勒冈小道。
Another small tip: when going the batch file route, I like to be able to abort it in case I run it accidentally. So the batch file invokes the shutdown but leaves you at the command prompt afterwards.
Plus, since it's on a timer, you get about the same thrill as you do when hunting in The Oregon Trail.
您可能已经意识到这一点,但以防万一:只需在“运行”框中输入 shutdown -r(或任何您喜欢的命令)并按 Enter 键会更容易。
避免将批处理文件散落在各处。
You're probably aware of this, but just in case: it's much easier to just type
shutdown -r
(or whatever command you like) into the "Run" box and hit enter.Saves leaving batch files lying around everywhere.
当远程连接到计算机时(无论如何,目标是 Windows XP;我不确定目标 Windows Vista),尽管开始菜单上的“关闭”被替换为“断开会话”或类似的东西,应该有一个名为“Windows Security”的东西,它也可以做与 Ctrl + Alt + End 相同的事情,如所指出的欧文.
When remoted into a machine (target is Windows XP anyway; I am not sure about target Windows Vista), although Shutdown on the start menu is replaced by Disconnect Session or something like that, there should be one called 'Windows Security' which also does the same thing as Ctrl + Alt + End as pointed to by Owen.
我参加聚会迟到了,但还没有看到这个答案。
当您不想使用批处理文件或键入命令时。 您可以将焦点设置到桌面,然后使用 Alt + F4。
Windows 会询问你要做什么,选择关机或重新启动。
有关屏幕截图甚至视频,请参阅:https://tinkertry。 com/如何关闭或重新启动 Windows-over-rdp
I'm late to the party, but did not see this answer yet.
When you don't want to use a batch file or type the command. You can just set focus to the desktop and then use Alt + F4.
Windows will ask you what you want to do, select shutdown or restart.
For screenshots and even a video, see: https://tinkertry.com/how-to-shutdown-or-restart-windows-over-rdp
我会在 记事本 或 写字板 用于基本注销命令:
这与手动单击开始和注销基本相同,但如果您有批处理文件准备好了。
I would write this in Notepad or WordPad for a basic logoff command:
This is basically the same as clicking start and logoff manually, but it is just slightly faster if you have the batch file ready.
shutdown 和
rundll32.exe shell32.dll,SHExitWindowsEx n命令。
注销 - 允许您通过 sessionid 或会话名称注销用户
PSShutdown - 需要从 Windows sysinternals 下载。
bootim.exe - Windows 10/8 关闭 iu
change/chglogon - 阻止新用户登录或进行另一个会话
NET SESSION /DELETE - 结束用户
wusa /forcerestart /quiet - Windows 更新管理器,还可以重新启动机器
tsdiscon - 断开您
rdpinit 的连接 -将您注销,尽管我目前找不到任何文档
Some additions to the shutdown and
rundll32.exe shell32.dll,SHExitWindowsEx n
commands.LOGOFF - allows you to logoff user by sessionid or session name
PSShutdown - requires a download from windows sysinternals.
bootim.exe - windows 10/8 shutdown iu
change/chglogon - prevents new users to login or take another session
NET SESSION /DELETE - ends a session for user
wusa /forcerestart /quiet - windows update manager but also can restart the machine
tsdiscon - disconnects you
rdpinit - logs you out , though I cant find any documentation at the moment