 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Boskoop
Joined: 01 Jan 2005 Posts: 75
|
Posted: Mon Aug 07, 2006 7:18 pm Post subject: Wake-up-timer/ Scheduler-Function |
|
|
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 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:
| Code: | ; 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)
} |
|
|
| Back to top |
|
 |
halllon
Joined: 29 Nov 2007 Posts: 16
|
Posted: Fri Jun 06, 2008 8:53 am Post subject: |
|
|
This promises to be a great script for a project I am doing.
Is it possible to have a key press make the computer resume from sleep mode with this script? |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Jun 08, 2008 7:56 pm Post subject: |
|
|
You might be interested in AHK-Scheduler, some sort of Windows Scheduled Tasks clone. AHK-Scheduler is using this function.
| Quote: | | Is it possible to have a key press make the computer resume from sleep mode with this script? |
My computer wakes up on any mouse movement or key press while in sleep mode. In hibernate mode, I have to push the ON-button. I don't know if its possible at all to wake a computer from hibernate mode by a key press.
Boskoop |
|
| Back to top |
|
 |
Poolee Guest
|
Posted: Mon Jun 23, 2008 1:06 am Post subject: |
|
|
Only if it's support by your BIOS. My last computer's BIOS had an option to allow any key or a password to wake the computer from off or hibernation.
Cheers
Paul |
|
| Back to top |
|
 |
gahks Guest
|
Posted: Fri Jan 09, 2009 1:45 pm Post subject: Thanks |
|
|
Just what I was looking for, great. Works fine on XPSP2.
Cheers,
gahks |
|
| Back to top |
|
 |
sabukz
Joined: 15 Dec 2009 Posts: 21
|
Posted: Tue Feb 23, 2010 6:05 am Post subject: |
|
|
could one explain the above script _________________ Cheers! |
|
| Back to top |
|
 |
RandomUser Guest
|
Posted: Thu Apr 01, 2010 2:13 am Post subject: Variable not correct |
|
|
| I'm not extremely well versed in this, but I was using this script and having errors and not waking up at the correct time. The "minute" parameter is specified as "Min" (instead of "Minute") later in the script. Once I changed the "Min" parameter to "Minute", it worked great. Again, I'm not an expert and I'm not 100% sure this was the problem, but once I changed it the program worked fine. |
|
| Back to top |
|
 |
Pooja Guest
|
Posted: Thu Feb 02, 2012 12:31 pm Post subject: How to repeat daily? |
|
|
hi,
I want to hibernate at 9Pm and wake up at 8.30am daily. how to run this program ? please help  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|