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.
I found this topic while searching for run script for startup and shutdown Windows 10. Those answers above didn't working. For me on windows 10 worked when I put scripts to task scheduler. How to do this: press window key and write Task scheduler, open it, then on the right is Add task... button. Here you can add scripts. PS: I found action for startup and logout user, there is not for shutdown.
Create your own shutdown script - called Myshutdown.bat - and do whatever you were going to do in your script and then at the end of it call shutdown /a. Then execute your bat file instead of the normal shutdown.
(See http://www.w7forums.com/threads/run-batch-file-on-shutdown.11860/ for more info.)
You can create a local computer policy on Windows. See the TechNet at http://technet.microsoft.com/en-us/magazine/dd630947
gpedit.msc
to open the Group Policy Editor,For the above code to function; you need to make sure the following directories exist (mine didn't). Just add the following to a bat and run it:
It's just that GP needs those directories to exist for:
to function properly.
Well, its an easy way of doing some registry changes: I tried this on 2008 r2 and 2016 servers.
Things need to be done:
Save this file as regedit.reg extension
Run it on any command line using below command: