user3747357
user3747357

Reputation: 71

How to run a bat file before windows shut down?

I am trying to run a BAT file immediately before Windows shutdown. I've tried the method shown in the question below:

Executing a batch script on Windows shutdown

However, the file does not run.

I did not specify any parameters for the BAT file (see attached image below):

enter image description here

Should I add parameters in order for it to run? I am on Windows 8.1.

Upvotes: 7

Views: 14126

Answers (5)

Matthew Smith
Matthew Smith

Reputation: 510

This possibly isn't working because the script line of the 'Windows Shutdown Properties' pop-up window where you entered the location of the .bat file, tells the computer to look for the location of a PowerShell file (.ps1), not a .bat file, hence the error. Enter the same file location on the 'Scripts' tab.

Alternatively, what I can suggest doing is creating a shortcut to the .bat file (for example on your desktop) and a when you want to shutdown your computer (and run the .bat file) click on the shortcut you created. After doing this, edit the .bat file and add this line of code to the end or where needed:

c:\windows\system32\shutdown -s -f -t 00

What this does it is

  1. Runs the shutdown process
  2. Displays a alert
  3. Forces all running processes to stop
  4. Executes immediately

Upvotes: 1

Eternal_Dusk
Eternal_Dusk

Reputation: 183

Navigate to the Local Group Policy Editor, then the shutdown properties then add a script like you did, but use the scripts tab, not powershell scripts. You do NOT need to run it as a powershell script unless it pulls things from powershell specifically.

Hope this helps!

Example

Upvotes: 3

user2648008
user2648008

Reputation: 152

it's likely that you missed gpupdate. the related symptom of script executing at system reboot is vaguely related to the GP settings applied on reboot by system itself.

Upvotes: 0

Kingzel
Kingzel

Reputation: 467

Very easy answer

Shortcuts that's all make a shortcut that makes a batch file run here i snapped somethingthe code of batch file for you

Here you have to make a shortcut for a batch file

Upvotes: 1

S Blas
S Blas

Reputation: 3

have your batch file be followed by this shutdown sequence c:\windows\system32\shutdown -s -f -t 00

Upvotes: -1

Related Questions