running a program before shutdown in Win7 and Win XP

五迷三道 提交于 2019-12-02 06:14:38

问题


I know that there are threads about this, I found this one: How to schedule a task to run when shutting down windows but it fails for me.

I wrote a little program in LabView and made an exe out of it. It runs perfect when I double click the exe in normal windows operation (it takes just a few seconds to complete). Then I put the exe in a batch file and that batch file in the group policy as a shutdown script. The result is that the computer hangs when shuting down. It shows the shutdown screen for minutes and I have to power cycle the PC to start it again. I even tried only a simple file copy command in the batch file with the same result. What am I doing wrong? Any hints are greatly welcome

Thanks a lot

Martin


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/28234346/running-a-program-before-shutdown-in-win7-and-win-xp

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