In this article, you will learn about different commands and ways to shut down, reboot, and log off the PC. You will learn about batch file shutdown commands in detail.
How to shutdown? |
How to log off? |
How to hibernate? |
How to reboot? |
Example: source code |
The command used to shut down computer is
shutdown /s /f /t 0
Follow these steps to shut down the computer using cmd.
The computer will shut down immediately after hitting this command.
Here are the steps to shut down a computer using a batch file.
Alternately the following code can be used for immediate shutdown.
SHUTDOWN /p
The code we stated above is used to shut down the computer immediately after hitting the code. We have to use the following command to set the timing for shutting down.
For example, the following code is used to shut down a computer in 60 seconds.
SHUTDOWN /s /t 60 /c
Logging off means signing out of from the current logged in account. Here is the code to log off or sign out.
SHUTDOWN /l
where l signifies shortcut command for logging off.
Hibernating is same as shutting down but when you hibernate your computer, it stores and remembers the previous state of the computer before hibernating and it will resume from there.
Here is the code to hibernate a computer.
SHUTDOWN /h
Here is the code required to reboot a computer, be it from command prompt or batch file.
Here is the code to reboot a computer.
SHUTDOWN -r -t 10
This is the code to reboot the computer in 10 seconds.
Let’s take an example where the user will be asked to enter an option whether to logoff or reboot or hibernate or to shutdown the computer.
Here is the source code.
@echo OFF
ECHO "Choose an option .."
ECHO "1 = Logoff"
ECHO "2 = Reboot"
ECHO "3 = Hibernate"
ECHO "4 = Shutdown"
SET /p option=Choose one option-
IF %option%==1 SHUTDOWN /l
IF %option%==2 SHUTDOWN -r -t 10
IF %option%==3 SHUTDOWN /h
IF %option%==4 SHUTDOWN /s /f /t 0
PAUSE
Save this as .bat file and double click on it to run. The output console will be like the following.
Now depending on the option you choose the computer will be either shut down, logoff, hibernate or reboot.