running a program before shutdown in Win7 and Win XP

谁说我不能喝 提交于 2019-12-02 02:15:15

thank you for your answer, it made me try some more things and now I was successful. I want to give some results here, maybe they help someone else:

  • Additional to the group policy where you specify the exe that shall run before shutdown there is another usefull setting that can be made in gpedit (I have a german Win 7 so maybe the names are not exactly what you have): computer configuration - adminstrative templates - system - scripts: there you find "run scripts at shutdown visible". If this is not activated you will not see what the computer does during shutdown. Not activated is the default
  • in gpedit under computer configuration - windows settings - scripts: shutdown you can insert as the script name a *.exe or if you want to run a batchfile use cmd.exe and enter as parameter /C "full path to batch\batchname.bat" (you need the /C and the quotes !!). In the thread mentioned in my question Dan Stevens says, giving the batchname.bat as the script name directly does not work. I didn't try this.

It's really nice to see my small program run just before shutdown

Thanks again for your help

Martin

I had to enable another option to make my AutoHotKey script (which i compiled into an .exe) before shutdown. The script would open an Excel file and add some values. In order to make it work I also had to enable the "Specify maximum wait time for Group Policy Scripts".

Just to make it more clear all the steps I had to do in Windows 10 set to UK English:

  1. Open Edit Group policy, by typing it into the Windows start menu for example.
  2. Go to Local Group Policy > Windows Setings > Scripts (Startup/Shutdown) > Shutdown
  3. Add your .exe here.
  4. Close window by clicking on OK.
  5. Go to Local Group Policy > Adminstrative Templates > System > Scripts
  6. Enable Display instructions in shutdown as they run.
  7. Enable Specify maximum wait time for Group Policy scripts. I set mine to 5000 ms.

Whenever I shutdown I first see the "Shutting down" and then the screen becomes black, it runs the script (opening Excel), closes Excel and then really shuts down.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!