00 Votes

Windows Batch Script: Computer Shutdown

Tutorial by Stefan Trost | Last update on 2021-04-30 | Created on 2013-11-03

With this little two-line batch script, you can simply shut down a Windows computer:

@echo off
%SYSTEMROOT%\system32\shutdown.exe -s -t 0

To use the script, just create a new blank plain text file, copy the 2 lines into it and change the file extension from "txt" to "bat".

If you then double-click on this file, it will automatically shut down the computer without demand.

This script can be used, for example, within big batch script files requiring a longer time in which, for instance, many actions are performed or a great number of programs are started and executed. If after running this script, the computer should be shut down, it is sufficient to insert this batch script to the bottom of the long script. So, you do not have to care about the shutdown anymore for yourself.

Delayed Computer Shutdown 

The 0 in the command indicates that the shutdown should be performed within 0 seconds. Using a different number there, makes the computer shut down with a delay. The parameter is always an integer in seconds.

Background

The script calls the program shutdown.exe that initiates the shutdown process of Windows. This program is located in the directory "system32" in the systems root folder. Since the absolute path to the system root folder can be different from computer to computer, we are using the constant "%SYSTEMROOT%" which always refers to the correct folder. Finally, it could be conceivable that someone has not installed Windows to C: or the folder varies from Windows version to Windows version.

Parameters

In addition, we are passing 2 parameters to shutdown.exe. The "-s" stands for shutdown. Instead, we can also use "-r" which will reboot (restart) the computer. As mentioned above, the "-t" is the time delay in seconds. If we are additionally passing the parameter "-f" in front of "-t", this forces a close of all running applications without warning.

ReplyPositiveNegative

About the Author

AvatarYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile

 

Related Topics

How to edit a Batch Script

Question | 1 Answer

Batch Script is not working

Question | 1 Answer

Abort Windows Batch Script

Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.