Executing a batch script on Windows shutdown

PNS picture PNS · Sep 15, 2012 · Viewed 117.7k times · Source

Is there any way, in Windows 7 Professional, to run a batch script (e.g., a .BAT file) when the user clicks on "shutdown" (not a batch file scheduled to shut down the machine, just one that runs only if the user clicks on "shutdown")?

Ideally, such a script would show the command prompt window and offer an option to cancel the shutdown procedure.

Solutions that do not require a third-party utility would be preferable.

Answer

bahrep picture bahrep · Sep 15, 2012

You can create a local computer policy on Windows. See the TechNet at http://technet.microsoft.com/en-us/magazine/dd630947

  1. Run gpedit.msc to open the Group Policy Editor,
  2. Navigate to Computer Configuration | Windows Settings | Scripts (Startup/Shutdown).

enter image description here