lgvlgv Posted January 11, 2012 Share Posted January 11, 2012 (edited) Hi all!I have a small problem that i cant figure out, its a program that connect to a management PC (for customer support, remote control) that i wrote..Every time older computers (windowsXP, never on win7) or busy computers shutdown or restart i get an error message. Windows says that my apps made a error and a popup message apper asking user to close the apps. if it is a faster computer the message just blink and windows is shutting down the PC anyway.how can i add/issue a shutdown command if PC reboots? So no error message popup when windows tryes to close the app.here is the codeexpandcollapse popupDo If TimerDiff($iBegin) > 6000 Then ; Loop until 1 min have passed _DebugOut("_settings()") _settings() _DebugOut("_updatedatabase()") ; _updatedatabase() $iBegin = TimerInit() EndIf If TimerDiff($iBegin1) > 600000 Then ; until 10 min passed If ping($MySQLServer) Then _MySQLUpdateSoft() EndIf $iBegin1 = TimerInit() EndIf Sleep(10) ; just to keep the program running Until $oClient.connect("_Recv", "_Receiving", "_LostConnection", "_TimedOut") > 0 _DebugOut("Client connected!") While $running $oClient.Process() If TimerDiff($iBegin) > 6000 Then ; Loop until 6 min have passed _settings() ; _updatedatabase() $iBegin = TimerInit() EndIf If TimerDiff($iBegin1) > 600000 Then ; until 10 sec passed If $MySQLServer <> "0.0.0.0" Then _MySQLUpdateSoft() EndIf $iBegin1 = TimerInit() EndIf Sleep(10) ; just to keep the program running WEnd Func _Recv($data) _DebugOut("Recv: " & $data) $data = StringSplit($data, "|", 2) _DebugOut("Recv: " & @IPAddress1 & ": " & $data[0]) Switch $data[0] Case $data[0] = "End" $oClient.Send("OK, Ending communication! Restarting client") Exit Case $data[0] = "ping" $oClient.Send("pong") Edited January 11, 2012 by lgvlgv Link to comment Share on other sites More sharing options...
LarsJ Posted January 12, 2012 Share Posted January 12, 2012 This example uses the WM_QUERYENDSESSION message to write the UTC time to a file (so you can see that it works) and then exits the script when the PC is rebooted or shutdown. May be you can use this. #include <Date.au3> Opt( "MustDeclareVars", 1 ) Global $WM_QUERYENDSESSION = 0x0011, $hGui MainProgram() Func MainProgram() $hGui = GUICreate( "Reboot/shutdown", 300, 200, -1, 300 ) GUIRegisterMsg( $WM_QUERYENDSESSION, "WM_QUERYENDSESSION" ) GUISetState() While 1 Switch GUIGetMsg() Case -3 ExitLoop EndSwitch WEnd GUIDelete( $hGui ) Exit EndFunc Func WM_QUERYENDSESSION( $hWnd, $msg, $wParam, $lParam ) If $hWnd = $hGui Then Local $time = _Date_Time_SystemTimeToDateTimeStr( _Date_Time_GetSystemTime(), 1 ) Local $fileName = @ScriptDir & "\" & StringLeft( @ScriptName, StringInStr( @ScriptName, ".", 0, -1 ) - 1 ) & ".txt" Local $file = FileOpen( $fileName, 1 ) FileWriteLine ( $file, $time ) FileClose( $file ) GUIDelete( $hGui ) Exit EndIf EndFunc You need a GUI. If your script don't have a GUI, you can add a dummy GUI and hide it. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
lgvlgv Posted January 12, 2012 Author Share Posted January 12, 2012 This example uses the WM_QUERYENDSESSION message to write the UTC time to a file (so you can see that it works) and then exits the script when the PC is rebooted or shutdown. May be you can use this. #include <Date.au3> Opt( "MustDeclareVars", 1 ) Global $WM_QUERYENDSESSION = 0x0011, $hGui MainProgram() Func MainProgram() $hGui = GUICreate( "Reboot/shutdown", 300, 200, -1, 300 ) GUIRegisterMsg( $WM_QUERYENDSESSION, "WM_QUERYENDSESSION" ) GUISetState() While 1 Switch GUIGetMsg() Case -3 ExitLoop EndSwitch WEnd GUIDelete( $hGui ) Exit EndFunc Func WM_QUERYENDSESSION( $hWnd, $msg, $wParam, $lParam ) If $hWnd = $hGui Then Local $time = _Date_Time_SystemTimeToDateTimeStr( _Date_Time_GetSystemTime(), 1 ) Local $fileName = @ScriptDir & "" & StringLeft( @ScriptName, StringInStr( @ScriptName, ".", 0, -1 ) - 1 ) & ".txt" Local $file = FileOpen( $fileName, 1 ) FileWriteLine ( $file, $time ) FileClose( $file ) GUIDelete( $hGui ) Exit EndIf EndFunc You need a GUI. If your script don't have a GUI, you can add a dummy GUI and hide it. i will try to see if i can integrate that? I dont have any files open om purpuse, exept the TCP session that is connected to my admin PC, maybe its becose i use but its over my head 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