Jump to content
tatane

[SOLVED]Not receiving WM_QUERYENDSESSION messages when script run as service

Recommended Posts

tatane
Posted (edited)

Hi,

As title says, my script doesn't receive ENDSESSION messages when running as service.

I'm sorry, I can't put an example but this is what I use :

_WinAPI_SetProcessShutdownParameters(0x3FF)
...
Global $hGui = GUICreate("")
Global Const $WM_QUERYENDSESSION = 0x11
GUIRegisterMsg($WM_QUERYENDSESSION, "onShutDownQuery")
Global Const $WM_ENDSESSION = 0x16
GUIRegisterMsg($WM_ENDSESSION, "onShutDownEnd")

...

Func onShutDownQuery($hWndGUI, $MsgID, $WParam, $LParam)
    log("query")
    
    Return False
EndFunc

Func onShutDownEnd($hWndGUI, $MsgID, $WParam, $LParam)
    ; cleanup ressources
    $bool_exit = True

    Return False
EndFunc

Should I use something else to detect shutdown/reboot/logoff and make some cleanup before ?

 

Thanks.

 

EDIT : I guess this is the cause of my problem  https://docs.microsoft.com/fr-fr/windows/desktop/Services/interactive-services

Edited by tatane

Share this post


Link to post
Share on other sites
Danyfirex

Hello Maybe this helps.

 

Saludos

  • Like 1

Share this post


Link to post
Share on other sites
tatane

Thanks Danyfirex. The service part is what I need !

It was easier than I thought. I added my cleanup code in _service_control() function where  $SERVICE_CONTROL_STOP and $SERVICE_CONTROL_SHUTDOWN are tested.

 

  • Like 1

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

×