WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Reboot and Shutdown Topics

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Run Script at Shutdown or Logoff

 Keywords: Shutdown Logoff Close Exit Run Execute Command Script

Question:

Is it possible to execute a single command, when a compiled winbatch closes? What I mean, when I run a winbatch with a infinite loop and the system shuts down, it comes with a question "do you want to close the winbatch?". I don't want that question, but I want to run a command. Is that possible?

Answer:

First, you can disable that script shutdown prompt using the following command at the beginning of your script:
   IntControl(12,5,0, 0, 0 )
To run WinBatch code on Windows shutdown.
Note: This is handled differently for different versions of windows. It actually is a very hard problem and you only have maybe 15-20 seconds before your program is cancelled by the system.

Option 1:

Windows also provides a set of policy-driven computer shutdown scripts that you can manage by using the Group Policy snap-in. Overview of Logon, Logoff, Startup, and Shutdown Scripts in Windows 2000 http://support.microsoft.com/?kbid=198642

Reference: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/How~To+Start~Program~Only~at~Windows~Shutdown.txt

Option 2:

Launch a WinBatch service (.exs) and have it monitor for the Shutdown/Logoff message, execute any shutdown/logoff code then exit! You can install the service on the fly using wntSvcCreate then start it using wntSvcStart.

Reference: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+Tutorials+Service~Scripts.txt


Article ID:   W18225
Filename:   Run Script at Shutdown or Logoff.txt
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38