Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a script for Windows to execute during system shutdown, follow these steps:

  1. Open Notepad or any text editor.
  2. Type in the commands you want to execute during shutdown. These could be any valid Windows commands or executables. For example, you could create a script that deletes temporary files or logs off all users before shutting down the system.

Example script:

@echo off
echo Deleting temporary files...
del %temp%\*.* /q /f
echo Logging off all users...
shutdown /l /f 
  1. Once you have written your script, save it with a .bat extension. For example, you could name it "shutdown-script.bat".
  2. Copy the script to the folder C:\Windows\System32.
  3. Open the Run dialog box by pressing the Windows key and R at the same time.
  4. Type in "gpedit.msc" and hit Enter.
  5. In the Local Group Policy Editor, navigate to Computer Configuration > Windows Settings > Scripts (Startup/Shutdown).
  6. Double-click on "Shutdown" in the right pane.
  7. Click on "Add" and browse to the script you created earlier.
  8. Click "OK" to exit from all the dialog boxes.

Now, whenever you shut down your Windows system, the script you created will be executed before the system shuts down completely.