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

DllCall Information

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

Keep from Going Into Standby

 Keywords: XP Standby Mode SetThreadExecutionState 

Question:

Was wondering if someone could help me with the syntax of a dllcall. I need to call SetThreadExecutionState in Kernel32.dll. Specifically, I need to set the ES_SYSTEM_REQUIRED value.

Here is the msdn on the function... http://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx

Reason. I have a Winbatch applet that performs power management on our manachines. After a set time of inactivity, I put the machine in standby mode. At midnight, WOL commands are issued to the workstations to wake the machines to prepare to recieve software distributions. The problem is where XP will automatically put the machine back in standby if there is no user activity within approx 2 minutes. The above call is "supposed" to keep XP from automatically going back into standby.

Answer:


;------------------------------------------------------------------------------------------------------------------------------------------
; SetThreadExecutionState
; Enables an application to inform the system that it is in use, thereby preventing the system from entering sleep or turning off the display while the application is running.
;
; ES_AWAYMODE_REQUIRED = 64  ; 0x00000040 ; Enables away mode. This value must be specified with ES_CONTINUOUS.
;                            ; Away mode should be used only by media-recording and media-distribution applications that must perform critical background processing on desktop computers while the computer appears to be sleeping. See Remarks.
;                            ; Windows Server 2003 and Windows XP/2000:  ES_AWAYMODE_REQUIRED is not supported.
ES_CONTINUOUS = 2147483648   ; 0x80000000 ; Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared.
; ES_DISPLAY_REQUIRED  = 2   ; 0x00000002 ; Forces the display to be on by resetting the display idle timer.
ES_SYSTEM_REQUIRED = 1       ; 0x00000001 ; Forces the system to be in the working state by resetting the system idle timer.
; ES_USER_PRESENT = 4        ; 0x00000004 ; This value is not supported. If ES_USER_PRESENT is combined with other esFlags values, the call will fail and none of the specified states will be set.
;                            ; Windows Server 2003 and Windows XP/2000:  Informs the system that a user is present and resets the display and system idle timers. ES_USER_PRESENT must be called with ES_CONTINUOUS.
; See also: http://msdn.microsoft.com/en-us/library/aa373208(VS.85).aspx
;------------------------------------------------------------------------------------------------------------------------------------------

; Note: Possible problem with WinBatch and integer values of DWORD type.
intPreviousState = DllCall ("KERNEL32.DLL", long : "SetThreadExecutionState", long : ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
; Rest of program goes here.
intPreviousState = DllCall ("KERNEL32.DLL", long : "SetThreadExecutionState", long : ES_CONTINUOUS)
Exit

Article ID:   W17793
Filename:   Keep XP from Going Into Standby.txt
File Created: 2013:01:03:13:44:42
Last Updated: 2013:01:03:13:44:42