Sign in to follow this  
Followers 0
speedy6

No shutown

8 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  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

Share this post


Link to post
Share on other sites

please just askingly. remove that code....


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

alrighty just on the side of caution...because on slow shutting down systems this can be used for not so nice behavior is all.


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

What is the matter? It a nice script and it works fine but with vista... had anyone a solution for that....

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