7

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.

Community
  • 1
  • 1
user3747357
  • 71
  • 1
  • 1
  • 3
  • 1
    possible duplicate of [How to schedule a task to run when shutting down windows](http://stackoverflow.com/questions/101647/how-to-schedule-a-task-to-run-when-shutting-down-windows) – npocmaka Jun 21 '14 at 13:25
  • 1
    the above post has to do with windows xp mainly. windows 7 - 8 operate differently. – user3747357 Jun 21 '14 at 15:16
  • Hold on ... that's a batch file, why are you adding it in on the "PowerShell Scripts" tab? – Harry Johnston Jun 21 '14 at 23:54
  • Should i simply add it to the Scripts tab? I tested it as well, but it didn't work. The strange thing is that the bat file runs when i restart my laptop, but it won't run when i hit the shutdown command. Also the bat file is within that folder C:\WINDOWS\System32\GroupPolicy\Machine\Scripts\Shutdown Any other suggestions? – user3747357 Jun 22 '14 at 04:29
  • Another thing that i noticed is that the script runs and displays the txt file that i want if i restart my laptop, but not when i shut it down. – user3747357 Jun 22 '14 at 05:31
  • I also noticed this - it runs when restarting PC but it does not run when I choose shutdown option. Have you maybe fixed this problem already? – user4341206 Jun 09 '15 at 12:31
  • Have you tried to call it via `cmd.exe /C "C:\Users\kiko\Documents\file.bat"`? – aschipfl Jul 29 '15 at 01:17
  • It worked for me; I created c:\OnShutdown.bat, which copies a file somewhere else, and hooked it up to the Shutdown event as above. If you change your batch file to do something similar, and/or change its location, do you get a different result? Btw, I'm on W7. – Ian Sep 21 '15 at 17:33

5 Answers5

3

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

Eternal_Dusk
  • 175
  • 12
1

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

Kingzel
  • 427
  • 4
  • 9
1

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
Matthew Smith
  • 508
  • 7
  • 22
0

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.

user2648008
  • 152
  • 4
-1

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

S Blas
  • 3
  • 3