Jump to content

script stops when shutting down/logging off windows


Recommended Posts

Hello,

I have a script that disables the LAN/WLAN and then start an app to connect to UMTS/3G.

If i close de app the connections will be enabled again, but when i shutdown, restart or log off in windows the script stops and the LAN/WLAN stay disabled.

Does somebody have a solution for this?

Gr. Bosland

Shortcut for app is a batch file;

@echo off

@cls

echo.

echo UMTS launcher...

echo.

runasspc /cryptfile:"disable.spc" /quiet (Runas as admin devcon tool to disable lan/wlan!!)

start HPCM.lnk

ping localhost -n 3 >nul

start processwaiter.exe

Proceswaiter.exe (created whit Autoit);

AutoItSetOption("TrayIconHide", 1)

ProcessWaitClose("gbxapp.exe")

Run("runasspc /cryptfile:enable.spc /quiet")

Link to comment
Share on other sites

Code below tells windows 1) to give the program priority in the shutdown queue and 2) receives a Windows message on shutdown, which gives you ~5 seconds (on Vista and Win7, I think on XP you can even abort the shutdown) to gracefully end your program (__ExitFunction()).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("My GUI")
GUISetState(@SW_SHOW)

#region ; This function sets a shutdown order for a process relative to the other processes in the system.
; http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx
#cs
    000-0FF = System reserved last shutdown range.
    100-1FF = Application reserved last shutdown range.
    200-2FF = Application reserved "in between" shutdown range.
    300-3FF = Application reserved first shutdown range.
    400-4FF = System reserved first shutdown range.
#ce
Global Const $SHUTDOWN_NORETRY = 0x00000001
DllCall("kernel32.dll", "BOOL", "SetProcessShutdownParameters", "DWORD", 0x3FF, "DWORD", $SHUTDOWN_NORETRY)
#endregion ; This function sets a shutdown order for a process relative to the other processes in the system.

#region ; The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions
; http://msdn.microsoft.com/en-us/library/aa376890%28v=VS.85%29.aspx
Global $WM_QUERYENDSESSION = 0x0011
GUIRegisterMsg($WM_QUERYENDSESSION, "WM_QUERYENDSESSION")
#endregion ; The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Func WM_QUERYENDSESSION($hWnd, $msg, $wParam, $lParam)
    Local Const $ENDSESSION_CLOSEAPP = 0x00000001
    ;ENDSESSION_CLOSEAPP
    ;The application is using a file that must be replaced, the system is being
    ;serviced, or system resources are exhausted. For more information, see Guidelines
    ;for Applications.

    Local Const $ENDSESSION_CRITICAL = 0x40000000
    ;ENDSESSION_CRITICAL
    ;The application is forced to shut down.

    Local Const $ENDSESSION_LOGOFF = 0x80000000
    ;ENDSESSION_LOGOFF
    ;The user is logging off. For more information, see Logging Off.

    Switch $lParam
        Case $ENDSESSION_CLOSEAPP
            ; MsgBox(0, "MSG", "ENDSESSION_CLOSEAPP")
        Case $ENDSESSION_CRITICAL
            ; MsgBox(0, "MSG", "ENDSESSION_CRITICAL")
        Case $ENDSESSION_LOGOFF
            ; MsgBox(0, "MSG", "ENDSESSION_LOGOFF")
    EndSwitch

    __ExitFunction()

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_QUERYENDSESSION

Func __ExitFunction()
    Exit
EndFunc   ;==>__ExitFunction

Edit: Meaning, in the _Exit function you can reenable the LAN connection...

Edited by KaFu
Link to comment
Share on other sites

I assume you're running in windows? Couldn't you put a batch file that runs

runasspc /cryptfile:enable.spc /quiet

in your startup folder?

The problem is that if another user want to log on, the lan is disabled... so that's not a solution
Link to comment
Share on other sites

Code below tells windows 1) to give the program priority in the shutdown queue and 2) receives a Windows message on shutdown, which gives you ~5 seconds (on Vista and Win7, I think on XP you can even abort the shutdown) to gracefully end your program (__ExitFunction()).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("My GUI")
GUISetState(@SW_SHOW)

#region ; This function sets a shutdown order for a process relative to the other processes in the system.
; http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx
#cs
    000-0FF = System reserved last shutdown range.
    100-1FF = Application reserved last shutdown range.
    200-2FF = Application reserved "in between" shutdown range.
    300-3FF = Application reserved first shutdown range.
    400-4FF = System reserved first shutdown range.
#ce
Global Const $SHUTDOWN_NORETRY = 0x00000001
DllCall("kernel32.dll", "BOOL", "SetProcessShutdownParameters", "DWORD", 0x3FF, "DWORD", $SHUTDOWN_NORETRY)
#endregion ; This function sets a shutdown order for a process relative to the other processes in the system.

#region ; The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions
; http://msdn.microsoft.com/en-us/library/aa376890%28v=VS.85%29.aspx
Global $WM_QUERYENDSESSION = 0x0011
GUIRegisterMsg($WM_QUERYENDSESSION, "WM_QUERYENDSESSION")
#endregion ; The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Func WM_QUERYENDSESSION($hWnd, $msg, $wParam, $lParam)
    Local Const $ENDSESSION_CLOSEAPP = 0x00000001
    ;ENDSESSION_CLOSEAPP
    ;The application is using a file that must be replaced, the system is being
    ;serviced, or system resources are exhausted. For more information, see Guidelines
    ;for Applications.

    Local Const $ENDSESSION_CRITICAL = 0x40000000
    ;ENDSESSION_CRITICAL
    ;The application is forced to shut down.

    Local Const $ENDSESSION_LOGOFF = 0x80000000
    ;ENDSESSION_LOGOFF
    ;The user is logging off. For more information, see Logging Off.

    Switch $lParam
        Case $ENDSESSION_CLOSEAPP
            ; MsgBox(0, "MSG", "ENDSESSION_CLOSEAPP")
        Case $ENDSESSION_CRITICAL
            ; MsgBox(0, "MSG", "ENDSESSION_CRITICAL")
        Case $ENDSESSION_LOGOFF
            ; MsgBox(0, "MSG", "ENDSESSION_LOGOFF")
    EndSwitch

    __ExitFunction()

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_QUERYENDSESSION

Func __ExitFunction()
    Exit
EndFunc   ;==>__ExitFunction

Edit: Meaning, in the _Exit function you can reenable the LAN connection...

I tried but get an error from Windows;

Can't initialize .....

Link to comment
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
 Share

  • Recently Browsing   0 members

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