AutoHotkey Community

It is currently May 27th, 2012, 8:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: August 7th, 2006, 8:18 pm 
Offline

Joined: January 1st, 2005, 11:54 am
Posts: 75
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)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 6th, 2008, 9:53 am 
Offline

Joined: November 29th, 2007, 4:18 pm
Posts: 16
This promises to be a great script for a project I am doing. :D

Is it possible to have a key press make the computer resume from sleep mode with this script?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2008, 8:56 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2008, 2:06 am 
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


Report this post
Top
  
Reply with quote  
 Post subject: Thanks
PostPosted: January 9th, 2009, 2:45 pm 
Just what I was looking for, great. Works fine on XPSP2.

Cheers,
gahks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2010, 7:05 am 
Offline

Joined: December 15th, 2009, 3:29 pm
Posts: 21
could one explain the above script

_________________
Cheers!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Variable not correct
PostPosted: April 1st, 2010, 3:13 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject: How to repeat daily?
PostPosted: February 2nd, 2012, 1:31 pm 
hi,

I want to hibernate at 9Pm and wake up at 8.30am daily. how to run this program ? please help :cry:


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], specter333 and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group