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

Functions

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

IntControl 1005


NOTICE:

IntControl 1005 was removed from documentation as it did not work as people wished. It worked on on Windows 95/98/ME machines, but was not at all satifactory on NT/2000/XP/2003 machines.


WORKAROUND:

This is a possible workaround for IntControl 1005 on NT platforms. The idea is to 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.
;Monitor for shutdown or Logoff
;Initialize variables for the SvcSetAccept function
SERVICE_ACCEPT_SHUTDOWN = 4 ;service notified of system shutdown
SERVICE_ACCEPT_LOGOFF = 32768 ; service notified of user logoff
;Initialize variables for the SvcSetState function
SERVICE_STATE_STOPPED = 1 ;The service is not running
SERVICE_STATE_STOP_PENDING = 3 ;The service is stopping
;Initialize variables for the SvcWaitForCmd function
SERVICE_CONTROL_SHUTDOWN = 5 ;Requests the service To perform;cleanup tasks because the system is shutting down
SERVICE_CONTROL_LOGOFF = 32768 ;Logoff notification

;Tell system that we want shutdown & logoff notifications
flag=SvcSetAccept( SERVICE_ACCEPT_SHUTDOWN| SERVICE_ACCEPT_LOGOFF)

;Set up error handling
IntControl(12,2+8,0,0,0) ;Tell WinBatch to not honor terminate and not complain on Windows Exit
IntControl(38,1,"errorlog.txt",0,0) ;Route errors to log file

While @TRUE
      code=SvcWaitForCmd(5000) ;Timeout in 5 seconds

      Switch code

         Case SERVICE_CONTROL_SHUTDOWN
               ;Shutdown notification received
               ;Approx. 20 seconds to process
               BoxText("Shutdown notification received")
               SvcSetState(SERVICE_STATE_STOP_PENDING)
               
               ;do stop cleanup work here

               SvcSetState(SERVICE_STATE_STOPPED)
               Exit ;Goodbye
               Break
         
         Case SERVICE_CONTROL_LOGOFF
               ;Logoff command received
               BoxText("Logoff command received")
               SvcSetState(SERVICE_STATE_STOP_PENDING)
               
               ;do stop cleanup work here
               
               SvcSetState(SERVICE_STATE_STOPPED)
               Exit ;Goodbye
               Break
         
      EndSwitch

EndWhile
;Note. The preceding loop never exits
Exit ; Just a formality

Article ID:   W16972
File Created: 2007:07:03:14:27:24
Last Updated: 2007:07:03:14:27:24