windowsbatch-filewindows-7shutdowngroup-policy

Executing a batch script on Windows shutdown


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.


Solution

  • You can create a local computer policy on Windows. See the TechNet at https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dn789197(v=ws.11)

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

    enter image description here