arong_lai 发表于 2008-7-1 11:37:47

如何进入休眠(或待机),且回复到系统.

请问:怎样在Vista 下进行休眠或待机(S3或S4)状态, 过1分钟后,又回复到系统. AU3代码如何实现

dingamao 发表于 2008-8-24 16:13:30

Shutdown函数在vista下可有效?本人的破电脑无法安装这么高档的系统,只有期待你自己解决了,至于 待机指定时间后再唤醒,就我所知,别说au3,C++也做不到

aronglai 发表于 2009-9-29 13:48:20

here you are.


#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):   http://msdn.microsoft.com/library/default....error_codes.asp
;
; 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 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError)
    SetError(1)
    Return 0
EndIf
$result = DllCall("kernel32.dll", "long", "LocalFileTimeToFileTime", "ptr", $lpLocalFileTime, "ptr", $lpLocalFileTime)
If $result = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError)
    SetError(1)
    Return 0
EndIf
$result = DllCall("kernel32.dll", "long", "CreateWaitableTimer", "long", 0, "long", True, "str", "")
If $result = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError)
    SetError(1)
    Return 0
EndIf
DllCall("kernel32.dll", "none", "CancelWaitableTimer", "long",$result)

DllStructSetData($DueTime, 1, DllStructGetData($LocalFILETIME, 1))
DllStructSetData($DueTime, 2, DllStructGetData($LocalFILETIME, 2))

$result = DllCall("kernel32.dll", "long", "SetWaitableTimer", "long",$result, "ptr", $lpDueTime, "long", 1000, "long", 0, "long", 0, "long", true)
If $result = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError)
    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=False,$force=true)
    $result = DllCall("PowrProf.dll", "long", "SetSuspendState", "long",$mode, "long",$force, "long", false)
EndFunc







SetWakeUpTime(@HOUR,@min+6); wakeup the system in 6 minutes from now

SetSuspend(); go to hibernate mode

yarsye 发表于 2010-6-3 13:39:11

牛人 不牛不是你 这个功能你都能实现 佩服你aronglai
页: [1]
查看完整版本: 如何进入休眠(或待机),且回复到系统.