Jump to content

Recommended Posts

Posted

Is it possible in autoit to catch a shutown command from windows:

I want to start a scan when the user wants to shutdown the pc, after the scan i will shutdown the computer myself...

Is this possible?

Thanks.

Posted (edited)

You may test this, I found that here, but never used it since you can set permissions via mmc.

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
        ;Do stuff here
        ;do some more stuff here
        ;DoTheShutDownStuff();maybe do some more stuff here 
        ;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

As far as I remind, it just disables the shutdown-graphics, and since windows waits for them to appear, it wait as long as the script is running. :whistle:

Edited by dabus
Posted

Assuming that script actually works, there's really nothing wrong with it as it's just using the Windows API.

Posted

It's actually not such a big deal. If you specify the "force" flag during shutdown, WM_QUERYENDSESSION and WM_ENDSESSION aren't even sent. I'm not sure what flags the shell uses when you invoke shut down that way, but at worst, a user might have to use "shutdown -f" to ensure a forced shutdown.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...