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... 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 VonCI'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
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.