How to shut down or restart the computer with a batch file

Updated: 11/06/2021 by Computer Hope
shutdown command

Below are steps to restart, shut down, and hibernate a Windows computer from a batch file or the command line.

Note

There is no way to start or boot up a computer using a batch file. Running a batch file to execute an action against a computer requires the computer be turned on and an operating system to be loaded.

Windows Vista, 7, 8, and 10

Microsoft Windows Vista, 7, 8, and 10 includes a command to shut down the computer through the command line, shortcut, or batch files. Below are the steps required for creating a shutdown, restart, and hibernate shortcut.

  1. Create a new shortcut.
  1. For the location of the shortcut, enter one of the following commands, depending on what you want to do.

To shut down the computer, type the following line in the location text field.

shutdown.exe /s /t 00

To restart the computer, type the following line in the location text field.

shutdown.exe /r /t 00

To hibernate the computer, type the following line in the location text field.

shutdown.exe /h
  1. Click Next, and then type Shut down, Restart, or Hibernate for the name of the shortcut. Once the shortcut is named, click Finish.
  • For additional information about the shutdown command, see our shutdown command page.

After completing the steps above, double-click the shortcut icon to shut down, restart, or put the computer in hibernation.

Tip

After the shortcut is created, assign the shortcut a keyboard shortcut to shut down the computer using the keyboard. For more information, see: How to create a Windows shortcut key.

Tip

To create a batch file, add any of the shutdown commands above in the batch file with any other commands. For more information, see: How to make a batch file.

Shut down and restart shortcut in Windows XP

Microsoft Windows XP includes a new shutdown command that allows users to shut down the computer through the command line, shortcut, or batch files. Below are the steps required for creating a shutdown and restart shortcut.

  1. Create a new shortcut.
  1. For the location of the shortcut, type one of the following commands, depending on what you want to do.

To shut down your computer, type the following line in the location.

shutdown.exe -s -t 00

To restart the computer, type the following line in the location.

shutdown.exe -r -t 00
  1. Click Next, and then for the name of the shortcut type Shut down or Restart and click Finish.

After completing the steps above, double-click the shortcut icon to shut down or restart the computer.

Shut down and restart shortcut in Windows 95, 98, and Me

Create a batch file with the following lines, corresponding to the action you want to perform.

Restarting the computer

START C:\Windows\RUNDLL.EXE user.exe,exitwindowsexec
exit

Shut down the computer

C:\Windows\RUNDLL32.EXE user,exitwindows
exit
Note

When typing the two lines above, spacing is important. Also, make sure to enter the exit line at the bottom of the batch file in case Windows cannot restart the computer because of the open MS-DOS window.

Microsoft Windows 98 and Windows Me users can also run the following command to perform different forms of rebooting or shutting down.

rundll32.exe shell32.dll,SHExitWindowsEx n

Where n equals one of the numbers below, depending on the action you want the computer to perform.

  • 0 - LOGOFF
  • 1 - SHUTDOWN
  • 2 - REBOOT
  • 4 - FORCE
  • 8 - POWEROFF

Shut down and restart shortcut in MS-DOS

If you need to restart from MS-DOS, see the debug routines page for steps to write a debug routine to restart these computers.