Ask Your Question
3

How to create a script for Windows to execute during system shutdown?

asked 2022-04-09 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-19 10:00:00 +0000

lakamha gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-04-09 11:00:00 +0000

Seen: 13 times

Last updated: Feb 19 '22