bastel123 Posted February 11, 2006 Share Posted February 11, 2006 (edited) Hi, if you want to hibernate your system and wake it up at a specific time you can try this code : expandcollapse popup#include <date.au3> ;=============================================================================== ; ; Description: Sets a wakeup time to wake it up if the system / computer is hibernating or standby ; Parameter(s): $Hour - Hour Values : 0-23 ; $Minute - Minutes Values: 0-59 ; $Day - Days Values : 1-31 (optional) ; $Month - Month Values : 1-12 (optional) ; $Year - Year Values : > 0 (optional) ; ; Requirement(s): DllCall ; Return Value(s): On Success - 1 ; On Failure - 0 sets @ERROR = 1 and @EXTENDED (Windows API error code) ; ; Error code(s): [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp]http://msdn.microsoft.com/library/default....error_codes.asp[/url] ; ; Author(s): Bastel123 aka Sebastian ; Note(s): - ; ;=============================================================================== func SetWakeUpTime($Hour,$Minute,$Day=@mday,$Month=@mon,$Year=@YEAR) $SYSTEMTIME = DllStructCreate("ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort") $lpSYSTEMTIME = DllStructGetPtr($SYSTEMTIME) $LOCALFILETIME=DllStructCreate("dword;dword") $lpLOCALFILETIME = DllStructGetPtr($LOCALFILETIME) $DueTime=DllStructCreate("dword;dword") $lpDueTime=DllStructGetPtr($DueTime) DllStructSetData($SYSTEMTIME, 1, $Year) DllStructSetData($SYSTEMTIME, 2, $Month) DllStructSetData($SYSTEMTIME, 3, _DateToDayOfWeek($Year,$Month,$Day)-1) DllStructSetData($SYSTEMTIME, 4, $Day) DllStructSetData($SYSTEMTIME, 5, $Hour) DllStructSetData($SYSTEMTIME, 6, $Minute) DllStructSetData($SYSTEMTIME, 7, 0) DllStructSetData($SYSTEMTIME, 8, 0) $result = DllCall("kernel32.dll", "long", "SystemTimeToFileTime", "ptr", $lpSystemTime, "ptr", $lpLocalFileTime) If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf $result = DllCall("kernel32.dll", "long", "LocalFileTimeToFileTime", "ptr", $lpLocalFileTime, "ptr", $lpLocalFileTime) If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf $result = DllCall("kernel32.dll", "long", "CreateWaitableTimer", "long", 0, "long", True, "str", "") If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf DllCall("kernel32.dll", "none", "CancelWaitableTimer", "long",$result[0]) DllStructSetData($DueTime, 1, DllStructGetData($LocalFILETIME, 1)) DllStructSetData($DueTime, 2, DllStructGetData($LocalFILETIME, 2)) $result = DllCall("kernel32.dll", "long", "SetWaitableTimer", "long",$result[0], "ptr", $lpDueTime, "long", 1000, "long", 0, "long", 0, "long", true) If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf return 1 EndFunc ;=============================================================================== ; ; Description: Set the computer in Hibernate or Standby Status ; Parameter(s): $Mode - Suspend mode : True=Hibernate, False=Suspend ; $Force - Force-Mode : True=the system suspends operation immediately ; False=FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation ; ; Requirement(s): DllCall ; ; Author(s): Bastel123 aka Sebastian ; Note(s): If the system does not support hibernate use the standby mode - ; ;=============================================================================== Func SetSuspend($mode=true,$force=true) $result = DllCall("PowrProf.dll", "long", "SetSuspendState", "long",$mode, "long",$force, "long", false) EndFunc SetWakeUpTime(@HOUR,@min+2); wakeup the system in 2 minutes from now SetSuspend(); go to hibernate mode I hope it works on your computer's Sebastian Edited February 11, 2006 by bastel123 Link to comment Share on other sites More sharing options...
rakudave Posted February 11, 2006 Share Posted February 11, 2006 hmm, looks nice! (and please use the "code"-tags next time...) Pangaea Ruler new, UDF: _GUICtrlCreateContainer(), Pangaea Desktops, Pangaea Notepad, SuDoku, UDF: Table Link to comment Share on other sites More sharing options...
gomi Posted April 6, 2006 Share Posted April 6, 2006 Hi, I'm trying to write a script that puts my system into stand by and then wakes it up for work purposes. When I try to use your code, I got compile errors saying that the following functions are not defined: DllStructCreate() DllStructGetPtr() DllStructSetData() DllStructGetData() Where do these come from? Any help would be much appreciated. Thx! Link to comment Share on other sites More sharing options...
Busti Posted April 6, 2006 Share Posted April 6, 2006 Hi,I'm trying to write a script that puts my system into stand by and then wakes it up for work purposes.When I try to use your code, I got compile errors saying that the following functions are not defined:DllStructCreate()DllStructGetPtr()DllStructSetData()DllStructGetData()Where do these come from? Any help would be much appreciated. Thx! beta ^^ My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
GaryFrost Posted April 6, 2006 Share Posted April 6, 2006 look in my signature for where to get the beta. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
gomi Posted April 6, 2006 Share Posted April 6, 2006 ya... just found out too that dllstruct is only available in the beta... the code compiled alright for me now ^^ Link to comment Share on other sites More sharing options...
Diverge Posted April 6, 2006 Share Posted April 6, 2006 (edited) I just tried this out, and it ran the code just fine but nothing happens. I tried both $mode=true and $mode=false (hibernate and suspend), neither did anything, but also neither returns an error. My machine is running windows XP w/SP2, and has the PowrProf.dll (i checked to insure that I had the this dll it was calling). Edited April 6, 2006 by Diverge Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 6, 2006 Moderators Share Posted April 6, 2006 Are you running it in Beta? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Diverge Posted April 6, 2006 Share Posted April 6, 2006 (edited) Are you running it in Beta?Yep, othewise I would have gotten the errors the others got above. I guess I can compile it and try it on some other machines at work just for the hell of it... maybe it doesn't like my machine.Edit: Hmm, it seems it just doesn't like my work pc. I tried it on another pc in the lab and it worked just fine. Edited April 6, 2006 by Diverge Link to comment Share on other sites More sharing options...
Adam1213 Posted April 7, 2006 Share Posted April 7, 2006 It does not work for me. I have beta v3.1.1.118 (newest currently) How are you trying to get it to wake up exactly? schedule task may work (for more) if you are not using it IRC Client - 75 pages 3728 lines. Blob crumbler (game)Backup (drag to backup + cmd line)RS232 Link to comment Share on other sites More sharing options...
AutoItGal Posted July 24, 2007 Share Posted July 24, 2007 Hi, if you want to hibernate your system and wake it up at a specific time you can try this code : expandcollapse popup#include <date.au3> ;=============================================================================== ; ; Description: Sets a wakeup time to wake it up if the system / computer is hibernating or standby ; Parameter(s): $Hour - Hour Values : 0-23 ; $Minute - Minutes Values: 0-59 ; $Day - Days Values : 1-31 (optional) ; $Month - Month Values : 1-12 (optional) ; $Year - Year Values : > 0 (optional) ; ; Requirement(s): DllCall ; Return Value(s): On Success - 1 ; On Failure - 0 sets @ERROR = 1 and @EXTENDED (Windows API error code) ; ; Error code(s): [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp]http://msdn.microsoft.com/library/default....error_codes.asp[/url] ; ; Author(s): Bastel123 aka Sebastian ; Note(s): - ; ;=============================================================================== func SetWakeUpTime($Hour,$Minute,$Day=@mday,$Month=@mon,$Year=@YEAR) $SYSTEMTIME = DllStructCreate("ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort") $lpSYSTEMTIME = DllStructGetPtr($SYSTEMTIME) $LOCALFILETIME=DllStructCreate("dword;dword") $lpLOCALFILETIME = DllStructGetPtr($LOCALFILETIME) $DueTime=DllStructCreate("dword;dword") $lpDueTime=DllStructGetPtr($DueTime) DllStructSetData($SYSTEMTIME, 1, $Year) DllStructSetData($SYSTEMTIME, 2, $Month) DllStructSetData($SYSTEMTIME, 3, _DateToDayOfWeek($Year,$Month,$Day)-1) DllStructSetData($SYSTEMTIME, 4, $Day) DllStructSetData($SYSTEMTIME, 5, $Hour) DllStructSetData($SYSTEMTIME, 6, $Minute) DllStructSetData($SYSTEMTIME, 7, 0) DllStructSetData($SYSTEMTIME, 8, 0) $result = DllCall("kernel32.dll", "long", "SystemTimeToFileTime", "ptr", $lpSystemTime, "ptr", $lpLocalFileTime) If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf $result = DllCall("kernel32.dll", "long", "LocalFileTimeToFileTime", "ptr", $lpLocalFileTime, "ptr", $lpLocalFileTime) If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf $result = DllCall("kernel32.dll", "long", "CreateWaitableTimer", "long", 0, "long", True, "str", "") If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf DllCall("kernel32.dll", "none", "CancelWaitableTimer", "long",$result[0]) DllStructSetData($DueTime, 1, DllStructGetData($LocalFILETIME, 1)) DllStructSetData($DueTime, 2, DllStructGetData($LocalFILETIME, 2)) $result = DllCall("kernel32.dll", "long", "SetWaitableTimer", "long",$result[0], "ptr", $lpDueTime, "long", 1000, "long", 0, "long", 0, "long", true) If $result[0] = 0 Then Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") SetExtended($lastError[0]) SetError(1) Return 0 EndIf return 1 EndFunc ;=============================================================================== ; ; Description: Set the computer in Hibernate or Standby Status ; Parameter(s): $Mode - Suspend mode : True=Hibernate, False=Suspend ; $Force - Force-Mode : True=the system suspends operation immediately ; False=FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation ; ; Requirement(s): DllCall ; ; Author(s): Bastel123 aka Sebastian ; Note(s): If the system does not support hibernate use the standby mode - ; ;=============================================================================== Func SetSuspend($mode=true,$force=true) $result = DllCall("PowrProf.dll", "long", "SetSuspendState", "long",$mode, "long",$force, "long", false) EndFunc SetWakeUpTime(@HOUR,@min+2); wakeup the system in 2 minutes from now SetSuspend(); go to hibernate mode I hope it works on your computer's Sebastian Hi, I want to do looping for both standby and hibernate. Can anyone help me? I am new in Auto It. a) Standby/ Hibernate for 1 minute. Resume from Standby / Hibernate. c) Wait for 1 minute then Standby / Hibernate again. d) Repeat Step b and c for 10 times. Link to comment Share on other sites More sharing options...
ResNullius Posted July 25, 2007 Share Posted July 25, 2007 @bastel123 Is there a way to send the wakeup command immediately after hibernation occurs? See this post/thread for reasoning: http://www.autoitscript.com/forum/index.ph...st&p=357459I've tried setting the wakeup time to 1 minute from now, but there still tends to be a lag of about 15 seconds between complete hibernation and wake up. And I imagine that would fluctuate depending on the computer being used. Any thoughts? Thanks, great job BTW. Link to comment Share on other sites More sharing options...
fabdel Posted October 22, 2015 Share Posted October 22, 2015 This works on Windows XP?that language is?Thankyou Link to comment Share on other sites More sharing options...
Ontosy Posted February 4, 2016 Share Posted February 4, 2016 SetWaitableTimer not work in Windows 10. Do you have a fix? Link to comment Share on other sites More sharing options...
BrewManNH Posted February 4, 2016 Share Posted February 4, 2016 This thread is 9 years old, what have YOU done to try and get this to work? Most of the people in this thread haven't been here in years, so I don't think they'll be answering you any time soon. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
adcrazynoga Posted February 1, 2018 Share Posted February 1, 2018 It work fine, but just for AC mode. I dont know why when i plug out. It doesn't work for battery mode. Anyone can help me ? Link to comment Share on other sites More sharing options...
BrewManNH Posted February 1, 2018 Share Posted February 1, 2018 No, no one can help you. This thread is now 11 years old, and as my post just above yours states, most of these posters haven't been here in nearly a decade. Open a new thread and show what you've tried. adcrazynoga 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
adcrazynoga Posted February 3, 2018 Share Posted February 3, 2018 Thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now