Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Hibernation Wake Up Timer / Task Scheduler

  • Please log in to reply
5 replies to this topic
  • Members
  • 32 posts
  • Last active: Feb 23 2011 02:52 AM
  • Joined: 10 Jan 2009
I created a simple GUI for Bosknop's Hibernation wake up timer / Task Scheduler script, which I found here: http://www.autohotke...topic11620.html

I thought I'd share

It can
- restore the PC from standby mode at specified time to perform a task
- restore the PC from hibernation at specified time to perform a task, which I found extremely useful
- hibernate the PC
- place the PC in standby mode.

GUI todo: simple task scheduler feature

Download the compiled exe from here: https://ahknet.autoh...hks/hwtimer.exe

Download the source from here: https://ahknet.autoh...hks/hwtimer.ahk

And the Ico file which I found at wikimedia.com from here: https://ahknet.autoh.../~gahks/hwt.ico

Tested on XPProSP2.


AHK wake-up-timer/ scheduler provides some of the functions of Window's Task Scheduler or the command line tool "schtasks" as an AHK-script. Unlike Windows' Scheduled Tasks this function works with accounts without password.

The script can
1. Start a task at a given time
2. Wake the computer from standby at a given time to execute a task (optional)
3. Hibernate or suspend the computer (optional)

The script is testet on XPHome SP1 and XP Pro SP2. It should work on Windows98, Windows 2000 too. It's tested with AHK, but it should work with v1.0.36.07+. Wake up from Hibernate requires hardware support for S4-mode. You can find more info about standby-modes here

More than one timer
It's possible to start more than one timer, but every timer must be started in an own AHK-script.


Full Code:
;Delete standard menu, set custom menu items
Menu, tray, NoStandard
Menu, tray, add, &Help, MenuHelp
Menu, tray, add, &About, MenuAbout
Menu, tray, add, E&xit, ButtonCancel

;Get current local time, parse it, store lt in variables for the GUI Timer
FormatTime, CDate,, yyyy-M-d-H-m
Loop, parse, CDate, -,
	if A_Index = 1
	else if A_Index = 2
	else if A_Index = 3
	else if A_Index = 4

;Start GUI
Gui, Add, GroupBox, w330 h120, Timer Settings
Gui, Add, Text, ym+40 xm+10, Year | 
Gui, Add, Text, ym+40 x+5, Month | 
Gui, Add, Text, ym+40 x+5, Day
Gui, Add, Edit, ym+40 xm+150 w65
Gui, Add, UpDown, Wrap 0x80 vGUIYear Range2009-2050, %CYear%
Gui, Add, Edit, ym+40 w35 x+1
Gui, Add, UpDown, Wrap vGUIMonth Range1-12, %CMonth%
Gui, Add, Edit, ym+40 w35 x+1
Gui, Add, UpDown, Wrap vGUIDay Range1-31, %CDay%
Gui, Add, Text, ym+70 xm+10, Hour | 
Gui, Add, Text, ym+70 x+5, Minute
Gui, Add, Edit, ym+70 w35 xm+150
Gui, Add, UpDown, Wrap vGUIHour Range0-23, %CHour%
Gui, Add, Edit, ym+70 w35 x+1
Gui, Add, UpDown, Wrap vGUIMinute Range1-59, %CMin%
Gui, Add, Radio, vGUIHibernate ym+140 xm+10, Hibernate now (Ignore the timer)
Gui, Add, Radio, vGUIStandby ym+170 xm+10, Standby now (Ignore the timer)
Gui, Add, Radio, vGUIResume ym+200 xm+10, Schedule a restoration point from Hibernation/Standby mode
Gui, Add, Radio, vGUIHibernateResume ym+230 xm+10, Hibernate now and schedule a restoration point
Gui, Add, Radio, vGUIStandbyResume ym+260 xm+10, Standby now and schedule a restoration point
Gui, Add, Text, ym+300 xm+10, Select files to run
;File selection
Gui, Add, Edit, vFileToRunEdit1 ym+320 xm+20 w236
Gui, Add, Button, gOpen1 vFileToRun1 ym+320 xm+256 w50, Browse 
GuiControl, Disable, FileToRunEdit1
Gui, Add, Edit, vFileToRunEdit2 ym+350 xm+20 w236
Gui, Add, Button, gOpen2 vFileToRun2 ym+350 xm+256 w50, Browse 
GuiControl, Disable, FileToRunEdit2
Gui, Add, Edit, vFileToRunEdit3 ym+380 xm+20 w236
Gui, Add, Button, gOpen3 vFileToRun3 ym+380 xm+256 w50, Browse 
GuiControl, Disable, FileToRunEdit3
Gui, Add, Button, ym+430 xm+20 w133 Default, OK
Gui, Add, Button, ym+430 x+20 w133, Cancel
;Build menu and show GUI
Menu, FileMenu, Add, E&xit, ButtonCancel
Menu, HelpMenu, Add, &About, MenuAbout
Menu, HelpMenu, Add, &Help, MenuHelp
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu
Gui, Menu, MyMenuBar
Gui, Show, AutoSize, Hibernation Wake Up Timer

;File selection
Gui +OwnDialogs
FileSelectFile, RunAfterResume1, 3,, Selecting a file...
if RunAfterResume1 =  
GuiControl,, FileToRunEdit1, %RunAfterResume1%

Gui +OwnDialogs
FileSelectFile, RunAfterResume2, 3,, Selecting a file...
if RunAfterResume2 =  
GuiControl,, FileToRunEdit2, %RunAfterResume2%

Gui +OwnDialogs
FileSelectFile, RunAfterResume3, 3,, Selecting a file...
if RunAfterResume3 =  
GuiControl,, FileToRunEdit3, %RunAfterResume3%

;Cancel and X

;Help menu
IfWinExist, Hibernation Wake Up Timer Help
Gui +OwnDialogs
Gui, 3:Add, Tab2, w300 h330, Timer|Options||Select files|
Gui, 3:Add, Text,, Timer Settings:
Gui, 3:Add, Text,w270, Year format: YYYY | Month format: m | Day format: d 
Gui, 3:Add, Text,, Time format H (0-23) m (1-59)
Gui, 3:Add, Text,, Eg.
Gui, 3:Add, Text,w270, 11:02 PM - January 09, 2009
Gui, 3:Add, Text,, will be
Gui, 3:Add, Text,, 2009 1 9 - 23 2
Gui, 3:Tab, 2 
Gui, 3:Add, Text,, Wake up timer options:
Gui, 3:Add, Text, w270, Hibernate now (Ignore timer) - Hibernates your PC right away ignoring your file selections and timer settings.
Gui, 3:Add, Text, w270, Standby now (Ignore timer) - Activates the Standby mode right away ignoring your file selections and timer settings.
Gui, 3:Add, Text, w270, Schedule a restoration point... - You can specify a date and time, when your PC will be restored from Hibernated/Standby state automatically and three files to run right after your PC is restored.
Gui, 3:Add, Text, w270, Hibernate now and schedule... - Hibernates your PC right away restores it at the specified time, and runs the specified files.
Gui, 3:Add, Text, w270, Standby now and schedule... - Activates Standby mode right away restores your PC from Standby mode at the specified time, and runs the specified files.
Gui, 3:Add, Text,,
Gui, 3:Tab, 3
Gui, 3:Add, Text,, Select files:
Gui, 3:Add, Text, w270, You can specify three files to run after your PC is restored from Hibernated/Standby state.
Gui, 3:Show, AutoSize, Hibernation Wake Up Timer Help

Gui, 3:Destroy

;About menu
IfWinExist, About Hibernation Wake Up Timer
Gui, 2:Add, Text, w270, A simple GUI for Bosknop's Wake-up-timer/scheduler 
Gui, 2:Add, Text, w270, Wake up timer created by Bosknop
Gui, 2:Add, Text, w270, GUI created by gahks
Gui, 2:Add, Text, w270 xm cBlue g2LaunchWebsitegui, https://ahknet.autohotkey.com/~gahks/
Gui, 2:Add, Text, w270, Wake-up-timer's website: 
Gui, 2:Add, Text, w270 xm cBlue g2LaunchWebsite, http://www.autohotkey.com/forum/topic11620.html
Gui, 2:Add, Button, y+20 w100, Close
Gui, 2:Show, AutoSize, About Hibernation Wake Up Timer

Run https://ahknet.autohotkey.com/~gahks/

Run http://www.autohotkey.com/forum/topic11620.html

Gui, 2:Destroy

;OK Button
Gui, Submit

;End of GUI
;Setting variables, executing Bosknop's code
Month=%GUIMonth%   ;1-12
Day=%GUIDay%      ;1-31
Hour=%GUIHour%   ;0-23
Minute=%GUIMinute% ;1-59

if GUIHibernate = 1
else if GUIStandby = 1
else if GUIResume = 1
else if GUIHibernateResume = 1


;Last question
if (GUIResume = 1 or GUIHibernateResume = 1 or GUIStandbyResume = 1)
    MsgBox,,Timer settings, Your timer settings are: %Year%.%Month%.%Day% %Hour%:%Minute% (yyyy.m.d H:m) 
MsgBox, 4,Wake-up-timer GUI, Do you really want to continue? (Press YES or NO)
IfMsgBox No
IfMsgBox Yes

WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name)

if RunAfterResume1 <>
Run, %RunAfterResume1%

if RunAfterResume2 <>
Run, %RunAfterResume2%

if RunAfterResume3 <>
Run, %RunAfterResume3%


WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name)
;Awaits duetime, then returns to the caller (like some sort of "sleep until duetime").
;If the computer is in hibernate or suspend mode
;at duetime, it will be reactivated (hardware support provided)
;Parameters: Year, Month, Day, Hour, Minute together produce duetime
;Hibernate: If Hibernate=1, the function hibernates the computer. If Hibernate=2 the computer is set to
;         suspend-mode
;Resume: If Resume=1, the system is restored from power save mode at due time
;Name: Arbitrary name for the timer
    duetime:=GetUTCFileTime(Year, Month, Day, Hour, Minute)

            ,"char *", 0
            ,"Str",name, "UInt")


          ,"Uint", handle
          ,"Int64*", duetime        ;duetime must be in UTC-file-time format!
          ,"Int", 1000

    ;Hibernates the computer, depending on variable "Hibernate":
    If Hibernate=1       ;Hibernate
        DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
    If Hibernate=2      ;Suspend
       DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
            ,"Uint", handle
    DllCall("CloseHandle", uint, Handle)   ;Closes the handle

GetUTCFiletime(Year, Month, Day, Hour, Min)
;Converts "System Time" (readable time format) to "UTC File Time" (number of 100-nanosecond intervals since January 1, 1601 in  Coordinated Universal Time UTC)


    ;Converts System Time to Local File Time:
    VarSetCapacity(MyFiletime  , 64, 0)
    VarSetCapacity(MySystemtime, 32, 0)
    InsertInteger(Year,       MySystemtime,0)
    InsertInteger(Month,      MySystemtime,2)
    InsertInteger(DayOfWeek,  MySystemtime,4)
    InsertInteger(Day,        MySystemtime,6)
    InsertInteger(Hour,       MySystemtime,8)
    InsertInteger(Min,        MySystemtime,10)
    InsertInteger(Second,     MySystemtime,12)

    DllCall("SystemTimeToFileTime", Str, MySystemtime, UInt, &MyFiletime)
    LocalFiletime := ExtractInteger(MyFiletime, 0, false, 8)

    ;Converts local file time to a file time based on the Coordinated Universal Time (UTC):
    VarSetCapacity(MyUTCFiletime  , 64, 0)
    DllCall("LocalFileTimeToFileTime", Str, MyFiletime, UInt, &MyUTCFiletime)
    UTCFiletime := ExtractInteger(MyUTCFiletime, 0, false, 8)
    Return UTCFileTime

ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 32)
; Documented in Autohotkey Help
    Loop %pSize% 
        result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
    if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
        return result 
    return -(0xFFFFFFFF - result + 1)

InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; Documentated in Autohotkey Help
  Loop %pSize%
          DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index-1
                  , UInt, 1, UChar, pInteger >> 8*(A_Index-1) & 0xFF)


  • Members
  • 30 posts
  • Last active: Jul 31 2013 09:33 PM
  • Joined: 15 Jan 2008
Thank you for this GUI/script. :)

  • Members
  • 16 posts
  • Last active: Jul 07 2010 05:17 PM
  • Joined: 02 Jul 2010
This is great work. I wish the timer could be on a recurring basis. So I can set it to run the task the 1st of every month. But this is great.

  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Code can be heavily reduced:
Hibernate() w/ Wakeup
Just a remark.

  • Guests
  • Last active:
  • Joined: --
this func doesn't work on win7. anyone know why? :cry:

  • Members
  • 10 posts
  • Last active: Apr 29 2013 07:12 PM
  • Joined: 22 Oct 2010
I like the script and its a good thing. I got the problem that i cant turn monitor on after hibernation or sleep. I mean i need to click or touch something of my pc with my finger for him to go on... Is it normal and is there a way to make him go on automatic? Tried to make "Run" a script that turns him off and on but no effect :S

; Turn Monitor Off
Sleep, 1000
SendMessage, 0x112, 0xF170, 2,, Program Manager
; (2 = off, 1 = standby, -1 = on)

Is it my GPU that doesnt send signal to monitor or does the monitor go to some state i dont know?? Thx :)