To create a script for Windows to execute during system shutdown, follow these steps:
- Open Notepad or any text editor.
- 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
- Once you have written your script, save it with a .bat extension. For example, you could name it "shutdown-script.bat".
- Copy the script to the folder C:\Windows\System32.
- Open the Run dialog box by pressing the Windows key and R at the same time.
- Type in "gpedit.msc" and hit Enter.
- In the Local Group Policy Editor, navigate to Computer Configuration > Windows Settings > Scripts (Startup/Shutdown).
- Double-click on "Shutdown" in the right pane.
- Click on "Add" and browse to the script you created earlier.
- 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.