How to Make a Shutdown Bat File (Step-by-Step)
In this article
Creating a shutdown batch file is a simple way to turn off your Windows PC with a double-click, or even schedule it to run automatically. A .bat file contains plain text commands that Windows executes in the Command Prompt. This guide shows you exactly how to write, save, and test your own shutdown script, including options for delays, restarts, and forced shutdowns.
What You'll Need
- A Windows PC (Windows 10, 11, or earlier versions)
- Notepad (or any text editor like Notepad++)
- Basic file saving knowledge (you need to change the file extension)
Step-by-Step
- Open Notepad. Press Win + R, type
notepad, and press Enter. Alternatively, search for “Notepad” in the Start menu. - Type the shutdown command. The simplest command is:
shutdown /s /t 0
This shuts down immediately. If you want a delay (e.g., 60 seconds), replace0with60. - Add a comment (optional). Start a line with
REMto add a note, like:
REM This shuts down the PC after 60 seconds - Save the file. Click File > Save As. In the “Save as type” dropdown, choose All Files (*.*).
- Name it with a .bat extension. For example, type
shutdown.bat. Make sure the filename ends with.bat(not .txt). - Choose a location. Save it on your Desktop or any folder you prefer. Click Save.
- Test it (optional but recommended). Double-click the file. If you used a delay, you can abort it by opening Command Prompt and typing
shutdown /awithin the delay period.
Common Mistakes
- Forgetting to change “Save as type” to “All Files”. If you leave it as “Text Documents”, Notepad will save as
shutdown.bat.txt, which won’t run as a batch file. - Using the wrong slash. Windows commands use backslash
\for paths, but command-line options use forward slash/. Always type/s, not\s. - Typing extra spaces or characters. For example,
shutdown /s /t 0works, butshutdown /s /t 0(trailing space) is fine, butshutdown /s /t 0;is not. - Confusing shutdown with restart.
/rrestarts,/sshuts down. Using the wrong one will do the opposite of what you intended.
Tips
- Use a delay to avoid accidental shutdown. Set
/t 30to give yourself 30 seconds to cancel if you change your mind. - Add a message. Use
/c "message"to display a comment in the shutdown dialog, e.g.,shutdown /s /t 60 /c "System going down for maintenance". - Force close apps. Add
/fto force running programs to close without warning. Be careful: you may lose unsaved work. - Create a restart file too. Make a second .bat with
shutdown /r /t 0for quick restarts. - Run as administrator if needed. Some shutdown options (like
/f) may require admin rights. Right-click the .bat file and select “Run as administrator”.
Troubleshooting
- Double-clicking does nothing. Check the file extension. It must be
.bat, not.txt. Open the folder and enable “File name extensions” in View tab to see the full name. - An error says “shutdown” is not recognized. This is rare, but if it happens, use the full path:
C:\Windows\System32\shutdown.exe /s /t 0. - The PC shuts down immediately instead of waiting. Verify the
/tparameter is correct. The syntax is/tfollowed by a space and the number of seconds. If you wrote/t0(no space), it may be ignored. - You accidentally started a shutdown and want to cancel. Open Command Prompt and type
shutdown /a. This aborts the shutdown if you do it before the timer ends. - The file opens in Notepad instead of running. This means the extension is still .txt. Rename the file from
shutdown.bat.txttoshutdown.batmanually.
Frequently Asked Questions
Can I make the batch file shut down after a specific time?
Yes. Use shutdown /s /t 3600 for a 1-hour delay (3600 seconds). You can also use the Task Scheduler to run the .bat at a specific time.
How do I make a batch file that restarts the PC?
Replace /s with /r. Example: shutdown /r /t 0 restarts immediately.
Can I force-close all programs before shutdown?
Yes, add /f to the command: shutdown /s /f /t 0. This forces running apps to close without saving, so use it cautiously.
Is it possible to cancel a shutdown started by the batch file?
Yes, if you set a delay. Open Command Prompt and type shutdown /a. This works only if the timer hasn’t reached zero.
Can I make the batch file show a message before shutting down?
Yes, use /c "Your message". For example: shutdown /s /t 60 /c "Saving work...". The message appears in the system notification.
Do I need to run the .bat file as administrator?
Usually not for basic shutdown. But if you use /f or other advanced options, Windows may require admin rights. Right-click and choose “Run as administrator” if you get an access denied error.