Sometimes having a .bat file to restart/shutdown or logoff could be helpful. One common use case is when you need to restart or shutdown while using remote desktop (buttons will be disabled). In this article we will use the shutdown command that allow us to restart/shudown or logoff.
Using shutdown command
The batch file should contain a call to the shutdown command with the proper options.
For example for inmediate shutdown while connected using a remote desktop session:
shutdown -t 0 -r -f
If you want to add a 30 seconds to start the shutdown:
shutdown -t 30 -r
Here we list most of the common options for
shutdown -râ restarts
shutdown -sâ shutsdown
shutdown -lâ logoff
shutdown -t xxâ where
xxis number of seconds to wait till shutdown/restart/logoff
shutdown -iâ gives you a dialog box to fill in what function you want to use
shutdown -aâ aborts the previous shutdown command....very handy!
shutdown -hâ hibernate.
Shutdown command on remote sessions
When you are on a remote session (remote desktop), add the -f option to force the reboot. If you don't add -f, the session may close and can hang the windows.