MarcElser Posted March 1, 2011 Share Posted March 1, 2011 Hi, My script below runs "ssh.exe", but because of network outages, or network layer change from LAN to WLAN it sometimes crashes. Then my script restarts it that's working flawlessly. The problem ist when I try to shutdown the computer windows begins to close the applications. At some point in the shutdown process it also closes ssh.exe, but because my script is still running (I don't know why the shutdown process always kills ssh.exe first) it tries to restart ssh.exe. But ssh.exe can not be started anymore because windows is in shutdown mode and a messagebox with a red cross icon comes up saying the you cannot start applications while the computer is shutting down. My application then detects that ssh.exe has not been started and tries to restart it. This floods my screen with these messageboxes all over until I cancel the shutdown or windows closes the autoit script. So I tried not to restart ssh.exe once shutdown has started but my script is notified far too late of the ENDSESSION event. The Messagebox I added comes up just before the script ist terminated, but until this notification arrives the script has already flooded the screen. Can anyone help please? If Not ProcessExists("ssh.exe") Then AutoItSetOption("TrayIconHide",1) Const $WM_ENDSESSION = 0x0016 , $ENDSESSION_CLOSEAPP = 0x1 , $ENDSESSION_CRITICAL = 0x40000000 ,$ENDSESSION_LOGOFF = 0x80000000 GUIRegisterMsg($WM_ENDSESSION , "Computer_Shutdown") GUICreate("Computer_Shutdown") GUISetSTate(@SW_HIDE) Global $b_ShutdownInitiated = False While 1 ShellExecuteWait("C:\Program Files\OpenSSH\bin\ssh.exe",'-F "C:\Program Files\OpenSSH\config" shadowsrealm',"C:\Program Files\OpenSSH","",@SW_HIDE) If $b_ShutdownInitiated = True then Exit EndIf WEnd EndIf ; http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx Func Computer_Shutdown($hwnd, $uMsg, $wParam, $lParam) $b_ShutdownInitiated = True Select Case $lParam = $ENDSESSION_CLOSEAPP $wParam = True Case $lParam = $ENDSESSION_CRITICAL Case $lParam = $ENDSESSION_LOGOFF MsgBox(0,"$ENDSESSION_LOGOFF","Computer_LOGOFF") Return False EndSelect MsgBox(0,"Computer_Shutdown","Computer_Shutdown") Return False EndFunc Thanks for any help Link to comment Share on other sites More sharing options...
Yashied Posted March 1, 2011 Share Posted March 1, 2011 You must set a high shutdown priority for your process relative to other processes in the system.SetProcessShutdownParameters() My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now