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 1.0.44.7, 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.
Boskoop
-----------------------------------------------------
Edit 2006-08-08:
Made it a function
Edit 2006-08-30:
+ CloseHandle
+ can suspend the computer
+ wake up to execute a task now optional
-----------------------------------------------------
This is a working script. Just change the start time:
; CONFIGURATION Year=2006 Month=8 ;1-12 Day=30 ;1-31 Hour=21 ;0-23 Minute=16 ;1-59 Hibernate=0 ;0, 1, 2 Resume=1 ;0,1 Name=%A_Now% ; AUTOEXECUTE WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name) msgbox, I'm awake and working! ; FUNCTIONS 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) Handle:=DLLCall("CreateWaitableTimer" ,"char *", 0 ,"Int",0 ,"Str",name, "UInt") DLLCall("CancelWaitableTimer","UInt",handle) DLLCall("SetWaitableTimer" ,"Uint", handle ,"Int64*", duetime ;duetime must be in UTC-file-time format! ,"Int", 1000 ,"uint",0 ,"uint",0 ,"int",resume) ;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) } Signal:=DLLCall("WaitForSingleObject" ,"Uint", handle ,"Uint",-1) 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) { DayOfWeek=0 Second=00 Millisecond=00 ;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) InsertInteger(Millisecond,MySystemtime,14) 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) }