我一直在使用远程桌面连接进入工作站。但在这种环境下,我无法使用开始菜单中的电源选项。我需要另一种方法来关闭或重新启动。

如何通过命令行控制计算机的电源状态?


当前回答

使用shutdown命令最常见的方法有:

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.

上面的命令可以与这些附加选项组合:

-f -强制程序退出。防止关机过程被卡住。 -t <seconds> -设置直到关机的时间。使用-t 0立即关机。 -c <message> -添加一个关闭消息。消息将在事件日志中结束。 -y -对所有关机查询强制回答“是”。 注意:此选项在任何官方文档中都没有记录。是由这些StackOverflow用户发现的。


我想确定一些其他的很好的答案也被提到了。这里没有特别的顺序。

JosephStyons的-f选项 从VonC使用rundll32 迪恩的运行框 从Kip远程关机

其他回答

当远程进入一台机器(目标是Windows XP;我不确定目标Windows Vista),尽管开始菜单上的关机被断开连接会话或类似的东西所取代,应该有一个叫做“Windows安全”,它也做同样的事情,如欧文指出的Ctrl + Alt +结束。

如果您在远程计算机上,您可能还想添加-f选项来强制重新启动。否则,您的会话可能会关闭,顽固应用程序可以挂起系统。

每当我想强制立即重新启动时,我都会使用这个方法:

shutdown -t 0 -r -f

对于一个更友好的“给他们一些时间”选项,你可以使用这个:

shutdown -t 30 -r

正如您在注释中看到的,超时暗示了-f。

Brutus 2006是一个为这些选项提供GUI的实用程序。

增加了shutdown和rundll32.exe shell32.dll, shexitwindowsexn命令。

LOGOFF -允许您通过会话id或会话名称注销用户

PSShutdown -需要从windows系统内部下载。

Bootim.exe - Windows 10/8关机iu

Change / chgloon—阻止新用户登录或使用另一个会话

NET SESSION /DELETE结束用户的会话

Wusa / forcerstart /quiet - Windows更新管理器,但也可以重新启动机器

断开你的连接

rdpinit -登录您,虽然我不能找到任何文档在此刻

另一个小技巧:当采用批处理文件路径时,我希望能够中止它,以防意外运行它。因此,批处理文件调用关机,但随后将您留在命令提示符处。

@echo off
echo Shutting down in 10 seconds. Please type "shutdown /a" to abort.
cmd.exe /K shutdown /f /t 10 /r

此外,由于它是在计时器上,你会得到与你在俄勒冈小径狩猎时相同的刺激。

使用shutdown命令最常见的方法有:

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.

上面的命令可以与这些附加选项组合:

-f -强制程序退出。防止关机过程被卡住。 -t <seconds> -设置直到关机的时间。使用-t 0立即关机。 -c <message> -添加一个关闭消息。消息将在事件日志中结束。 -y -对所有关机查询强制回答“是”。 注意:此选项在任何官方文档中都没有记录。是由这些StackOverflow用户发现的。


我想确定一些其他的很好的答案也被提到了。这里没有特别的顺序。

JosephStyons的-f选项 从VonC使用rundll32 迪恩的运行框 从Kip远程关机