How to shut down / restart the computer with a batch file.
Issue
How to shut down / restart the computer with a batch file.
Solution
It may be necessary after a batch file is completed its copying or installing process to restart the computer to complete that installation. Below are steps that can be used to restart a computer through a batch file.
Windows XP, Vista, and 7 users
Microsoft Windows XP includes a new shutdown command that will enable a user to shutdown the computer through the command line or batch files. Additional information about this command can be found on the shutdown command page.
Windows 95, Windows 98 and Windows ME Users
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 above two lines, spacing is important. It is also very important that the exit line be placed into the batch file as many times Windows may be unable to restart the computer because of the open MS-DOS window.
Microsoft Windows 98, and Windows ME users can also run the below command to perform different forms of rebooting or shutting down.
rundll32.exe shell32.dll,SHExitWindowsEx n
Where n is equal to one of the below numbers for the proper action.
- 0 - LOGOFF
- 1 - SHUTDOWN
- 2 - REBOOT
- 4 - FORCE
- 8 - POWEROFF
MS-DOS Users
If the computer needs to be restarted from MS-DOS, see the debug page for additional information on how to do this.
