Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Hibernate() w/ Wakeup


  • Please log in to reply
16 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
[color=red]Hibernate([/color] T="", O=0,  U="H" [color=red])[/color] { ; [color=indigo]by SKAN[/color]  www.autohotkey.com/forum/viewtopic.php?t=50733
 T += %O%,%U%                
 EnvSub, T, 16010101, S
 VarSetCapacity(FT,8), DllCall( "[color=#D62A00]LocalFileTimeToFileTime[/color]", Int64P,T:=T*10000000,UInt,&FT )
 If hTmr := DllCall( "[color=#D62A00]CreateWaitableTimer[/color]", UInt,0, UInt,0, UInt,0 )
 If DllCall( "[color=#D62A00]SetWaitableTimer[/color]", UInt,hTmr, UInt,&FT, UInt,1000, Int,0, Int,0, UInt,1 )
 If DllCall( "[color=#D62A00]PowrProf\SetSuspendState[/color]", UInt,1, UInt,0, UInt,0 )
    DllCall( "[color=#D62A00]WaitForSingleObject[/color]", UInt,hTmr,Int,-1 ), DllCall( "[color=#D62A00]CloseHandle[/color]",UInt,hTmr )
 Return A_LastError
}

Usage Examples:

Hibernate( 20100101 ) ; until a future Timestamp ( New Year )
Hibernate( A_Now, 600, "Seconds" )
Hibernate( A_Now, 30, "Minutes" )
Hibernate( A_Now, 2, "Hours" ) or Hibernate( Null, 2 )
Hibernate( A_Now, 7, "Days" )


Credit: Thanks to Boskoop's Wake-up-timer/ Scheduler-Function

kWo4Lk1.png

StreetRider@Large
  • Guests
  • Last active:
  • Joined: --
I can't beleive no one else has said this...


Thank you.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Let me be the first


Gee.. :oops: Thanks.

Update: Code optimised/crunched from 13 lines to 10 lines.

unknowingly
  • Members
  • 63 posts
  • Last active: Apr 16 2010 06:08 AM
  • Joined: 21 Nov 2009
wow, awesome!
thanks

GuestAHK
  • Guests
  • Last active:
  • Joined: --
SKAN, ... wow this is amazing and just what I was looking for! May I ask how, if I can have the function to do one more step?



When the computer resumes from hibernate, how do I have the monitor 'come alive' automatically? :) Is this possible?

foxer
  • Members
  • 5 posts
  • Last active: Jun 21 2015 10:32 PM
  • Joined: 23 Dec 2009

When the computer resumes from hibernate, how do I have the monitor 'come alive' automatically? :) Is this possible?


This is a good question; I am also looking for a way to do this. I usually make my computer hibernate by the Windows menu, but I need to run a task (namely, restart ad hoc Wi-Fi, as mentioned in this French article), either by Windows itself or by AutoHotKey when the computer restarts from hibernate.
Any ideas?

whynotmore
  • Members
  • 20 posts
  • Last active: Jul 06 2010 05:32 AM
  • Joined: 31 Dec 2009
We cannot seem to get this script to work. in the usage examples, are you saying to make T="" be T="A_NOW" ? or does the entire line, Hibernate( A_Now, 30, "Minutes" ) go before the first line of the script?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

does the entire line, Hibernate( A_Now, 30, "Minutes" ) go before the first line of the script?


Yes!

whynotmore
  • Members
  • 20 posts
  • Last active: Jul 06 2010 05:32 AM
  • Joined: 31 Dec 2009
When it goes into hibernate, the computer immediatly wakes back up. Now, it even does it when we use shutdown > hibernate.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
What OS? If Win7, the problem could be USB mouse. See here
:arrow: I googled for Hibernate problem immediately wakes up

whynotmore
  • Members
  • 20 posts
  • Last active: Jul 06 2010 05:32 AM
  • Joined: 31 Dec 2009
that is very strange. we are running windows XP sp3.
Where is the CreateWaitTimer, SetWaitTimer, LocalFileTimeToFileTime, and WaitForSingleObject DLL's stored? The only one that I can find is the PowrProf.dll Which looks like it sends it into hibernate. Are those DLLs created by the script?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

we are running windows XP sp3.


Same here.

Where is the CreateWaitTimer, SetWaitTimer, LocalFileTimeToFileTime, and WaitForSingleObject DLL's stored?


Them are available in Kernel32.dll which is loaded by windows on boot.
The functions in Kernel32.dll are readily available.. whereas for PowrProf.dll, AHK will load the DLL - call the function and unload it.

ddk__
  • Guests
  • Last active:
  • Joined: --
Hi SKAN. Scripts works awesome after quick testing =)!
How does those timestamps work? Can I set an exact time? Like 16:00 o'clock or something? : )

Thanks, ddk

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

How does those timestamps work?


The first parameter T should be a valid time stamp.
If you pass null or an empty variable, AHK will presume current date-time.

The second parameter O is offset. The time Value that will be added to T

The third parameter is U is timeUnits which will decide whether O is Seconds, Minutes, Hours, or Days

Please refer AHK Doc for EnvAdd command to understand the first line of my Function.

Can I set an exact time? Like 16:00 o'clock or something? : )


Yes!

You may call the function like: Hibernate( 201003151600 ) or may be,

WakeupTime := A_YYYY A_MM A_DD "[color=red]1600[/color]"
Hibernate( WakeupTime )


ddk__
  • Guests
  • Last active:
  • Joined: --
That's awesome - great work! 8)