Batch Scripts

Shut Down When a Program Closes

Pick a program, like a video export or an installer, and the PC shuts down (or restarts, or hibernates) as soon as it closes.

 

Windows only. Read the code before running any script you download. Your browser or Windows SmartScreen may warn about .bat files; choose "Keep" / "More info › Run anyway" if you trust it.

Keeps this tool on this device so it works without internet, even after a refresh.

Had fun, or did this help? I’d appreciate any donation :) Not needed, but money buys temporary happiness at least lol

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

  1. 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).
  2. Type it in, pick the action and download.
  3. 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:

  1. Click Copy code, open Notepad and paste.
  2. Choose File › Save as. Set Save as type to All files (*.*). This step matters: if it stays on "Text documents", Notepad quietly adds .txt.
  3. Type a name ending in .bat, like my-script.bat, and save. You can also type the name in quotes, "my-script.bat", which forces that exact name even on "Text documents".
  4. 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

CommandWhat it does
tasklist /FI "IMAGENAME eq name.exe"Lists running processes with that exact name.
find /I "name.exe" >nulSets errorlevel 0 if it was found, 1 if not.
:wait_end … goto wait_endChecks every 10 seconds until the program is gone.
shutdown /s /t 60Shuts 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