What it does
Video renders, big file copies, installers and game patchers usually close or finish at a time nobody can predict. Rather than guess with a timer, let the PC wait for the program itself.
This script waits until the program you name is running, then checks every 10 seconds whether it's still there. The moment it closes, the PC shuts down, restarts or hibernates. Shutdown and restart give Windows' usual 60-second warning, so you can still cancel.
How to use Shut Down When a Program Closes
- Find the program's name: open Task Manager, go to Details and look for it while it runs (for example HandBrake.exe, obs64.exe or setup.exe).
- Type it in, pick the action and download.
- Start the script any time before the program finishes, and leave its window open.
Making the .bat file yourself
The download button already gives you a ready-to-run .bat file. If you'd rather copy the code, or the download gets blocked, you can make the file yourself in Notepad:
- Click Copy code, open Notepad and paste.
- Choose File › Save as. Set Save as type to All files (*.*). This step matters: if it stays on "Text documents", Notepad quietly adds
.txt. - Type a name ending in
.bat, likemy-script.bat, and save. You can also type the name in quotes,"my-script.bat", which forces that exact name even on "Text documents". - Check the file's icon: a .bat file shows a gear-window icon, not a notepad page. Double-click it to run.
My file ended up as script.bat.txt and opens in Notepad. How do I fix it?
Windows hides file extensions by default, so the file looks like script.bat but is really script.bat.txt. Turn extensions on: in File Explorer, choose View › Show › File name extensions (Windows 11) or tick File name extensions on the View tab (Windows 10). Then rename the file, delete the .txt at the end, and click Yes when Windows asks if you're sure you want to change the extension.
How it works
| Command | What it does |
|---|---|
tasklist /FI "IMAGENAME eq name.exe" | Lists running processes with that exact name. |
find /I "name.exe" >nul | Sets errorlevel 0 if it was found, 1 if not. |
:wait_end … goto wait_end | Checks every 10 seconds until the program is gone. |
shutdown /s /t 60 | Shuts down after Windows' 60-second notice. /r restarts, /h hibernates. |
Shut Down When a Program Closes FAQ
The program closes but the PC doesn't shut down.
Some programs leave a helper process with the same name running, or use a different name for the part doing the work. Check Task Manager > Details while it works to find the right one.
Can it wait for a game update?
Yes, if the update runs in its own program (many patchers do). For Steam, which keeps running after downloads, use Shut Down When Downloads Finish instead.
How do I run a .bat file?
Double-click it. To see or edit the code, right-click it and choose Edit (or open it in Notepad). Scripts that need administrator rights say so; for those, right-click › Run as administrator.
Is this script uploaded or tracked?
No. The code is built in your browser from the settings above and downloaded straight to your PC.
Related
- Shut Down When Downloads Finish: Wait until downloads and game updates stop, then shut down, restart or hibernate.
- Shutdown Timer: Shut down, restart, hibernate or lock the PC after a delay.
- Force Close a Program: End frozen programs by name with one double-click.
- All batch scripts