Sign in to follow this  
Followers 0
passkalilo

How to abort Standby and hibernate ?

3 posts in this topic

#1 ·  Posted (edited)

Hi ,everyone!

I want write a programme to temprary block my computer to enter standby and hibernate , show a messagebox before enter these state, , How can I do this?

the following code is abort shutdown , How to make it that can be aborting standby?

Opt("TrayIconHide", 1)

$WM_QUERYENDSESSION = 0x0011
GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown")
GUICreate("PreventShutdownGUI")
GUISetSTate(@SW_HIDE)
Global $b_ShutdownInitiated = False


While 1
    If $b_ShutdownInitiated = True then
        MsgBox (0, "", "OMG!")
     ;Do stuff here
     ;do some more stuff here
     ;DoTheShutDownStuff();maybe do some more stuff here wink.gif
     ;Shutdown();Maybe you want to shutdown the computer when done
        Exit;otherwise, you just exit this script
    EndIf
    sleep(10)
WEnd

Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam)
;~   run(@ScriptDir & "\killpgm.exe")
    $b_ShutdownInitiated = True
    Return False
EndFunc
Edited by passkalilo

Share this post


Link to post
Share on other sites



Hi ,everyone!

I want write a programme to temprary block my computer to enter standby and hibernate , show a messagebox before enter these state, , How can I do this?

Is this required API hook ? I know the hibernate api is SetSuspendState, How can I hook it ?

Thank you very much for your help!

This could help.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This could help.

This topic is just discuss how to detect the monitor is on or off , blocking the standby event is not solved , May be I must solving this problem by hooking api , However, I don't know how to making it possible , I hope someone give me a example, I'm very appreciate,

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>

Opt('MustDeclareVars', 1)

Global $hHook, $hSuspend

_Main()

Func _Main()
    Local $hmod

    $hSuspend = DllCallbackRegister("SetSuspendState", "int", "int;int;int")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_GETMESSAGE, DllCallbackGetPtr($hSuspend), $hmod)


    While 1
        Sleep(10)
    WEnd
EndFunc  ;==>_Main


;===========================================================
; callback function
;===========================================================
Func SetSuspendState($nCode, $wParam, $lParam)
    MsgBox(0,$nCode,$wParam)
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc  ;==>_KeyProc

Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hSuspend)
EndFunc  ;==>OnAutoItExit

these code is not working , Why?

Edited by passkalilo

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0