Sign in to follow this  
Followers 0
Maffe811

Detecting Windows Shutdown

6 posts in this topic

After a quick search, this showed up:
'?do=embed' frameborder='0' data-embedContent>>

and one of the comments suggested this:

GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown")
GUICreate("PreventShutdownGUI")
GUISetSTate(@SW_HIDE)

; set highest notification level
If Not _SetProcessShutdownParameters(0xFFF) Then ; MSDN says maximum is 0x4FF, but it worked for me
    If Not _SetProcessShutdownParameters(0x4FF) Then ; MSDN says this is reserved for System, but worked for me
        _SetProcessShutdownParameters(0x3FF) ; highest not reserved number, if everything else does not work
    EndIf
EndIf

Global $b_ShutdownInitiated = False

While 1
    If $b_ShutdownInitiated = True then
        $b_ShutdownInitiated = False
        MsgBox(48 + 8192 + 262144, "Installer", "Ending your user session has been disabled to allow the installation to complete." _
        & @CRLF & @CRLF & "You will be able to shutdown/reboot/logoff once the installation process has completed." , 8)
    EndIf
    sleep(10)
WEnd

Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam)
    $b_ShutdownInitiated = True
    ; DO NOT ADD A MSGBOX HERE
    ; Windows shows a not responding box after ~5 secs and allows to kill your app.
    Return False
EndFunc


Func _SetProcessShutdownParameters($dwLevel, $dwFlags=0)
    ; <a href='http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx</a>
    ; Prog@ndy
    Local $aResult = DllCall("Kernel32.dll", "int", "SetProcessShutdownParameters", "dword", $dwLevel, "dword", $dwFlags)
    If @error Then Return SetError(1,0,0)
    Return $aResult[0]
EndFunc

And not 100% sure what everything does, but i can't even test it because this comes up:
 

WARNING: $WM_QUERYENDSESSION: possibly used before declaration.
GUIRegisterMsg($WM_QUERYENDSESSION,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

and i don't know what i need to do to fix it.

Any suggestions?


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites



Maffe811,

The WM_ suggests it is a "Windows Message" - and that is indeed where you find it. Just include WindowsConstants.au3. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Aaah... That makes sence!

Thanks!


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Can anyone explain me how to get, lets say a message box to pop up when the computer is shuttingdown/logging off ?
Cause i've tried making it work, but nothing makes it work.


GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown")
GUICreate("PreventShutdownGUI")
GUISetSTate(@SW_HIDE)

; set highest notification level
If Not _SetProcessShutdownParameters(0xFFF) Then ; MSDN says maximum is 0x4FF, but it worked for me
    If Not _SetProcessShutdownParameters(0x4FF) Then ; MSDN says this is reserved for System, but worked for me
        _SetProcessShutdownParameters(0x3FF) ; highest not reserved number, if everything else does not work
    EndIf
EndIf

Global $b_ShutdownInitiated = False

While 1
    If $b_ShutdownInitiated = True then
        $b_ShutdownInitiated = False
        MsgBox(48 + 8192 + 262144, "Installer", "Ending your user session has been disabled to allow the installation to complete." _
        & @CRLF & @CRLF & "You will be able to shutdown/reboot/logoff once the installation process has completed." , 8)
    EndIf
    sleep(10)
WEnd

Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam)
    $b_ShutdownInitiated = True
    ; DO NOT ADD A MSGBOX HERE
    ; Windows shows a not responding box after ~5 secs and allows to kill your app.
    Return False
EndFunc


Func _SetProcessShutdownParameters($dwLevel, $dwFlags=0)
    ; <a href='http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx</a>
    ; Prog@ndy
    Local $aResult = DllCall("Kernel32.dll", "int", "SetProcessShutdownParameters", "dword", $dwLevel, "dword", $dwFlags)
    If @error Then Return SetError(1,0,0)
    Return $aResult[0]
EndFunc

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Maffe811,

See the example for function _WinAPI_SetProcessShutdownParameters.

This is in the UDF _WinAPIEx.au3, just search the forum for it.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thank you! Exactly what i needed! 


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

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