jorgeng Posted January 22, 2008 Share Posted January 22, 2008 (edited) Hello! I have an important stock-program running daily on my pc which can buy/sell stocks and gets new data every minute. It's critical that the program is running on daytime. Some times a week my pc looses connection to router and adsl 8 mbit connection. Then the stock program can't work. The only way to get connection to internet again for the stock program is to restart the pc with vista ultimate, sad but true. So i need an autoit-script checking internet-connection and if no internet for 5 minutes then force the pc to reboot. Anyone knowing what to theck for, killing certain processes and restart them? Thanks for advice. Edited January 22, 2008 by jorgeng Link to comment Share on other sites More sharing options...
martin Posted January 22, 2008 Share Posted January 22, 2008 Hello!I have an important stock-program running daily on my pc which can buy/sell stocks and gets new data every minute.It's critical that the program is running on daytime.Some times a week my pc looses connection to router and adsl 8 mbit connection. Then the stock program can't work.The only way to get connection to internet again for the stock program is to restart the pc with vista ultimate, sad but true.So i need an autoit-script checking internet-connection and if no internet for 5 minutes then force the pc to reboot.Anyone knowing what to theck for, killing certain processes and restart them?Thanks for advice.The way I check for an internet connection isIf Ping('google.co.uk') > 0 Then;if I can see google then I have a connection. (Any url which is unlikely to disappear, maybe try 2 or 3 to be sure.)Look up ShutDown in the help.To restart running processes might be a little tricky if they don't start automatically. The ones you definitely need to run you can either either put in your startup folder or just get your script to Run them or ShellExecute them, but if they need some sort of interaction to get started you will have a bit more scripting to do.It might be worth trying to disable your Ethernet port and then anable it again to see if that works instead of rebooting.. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jorgeng Posted January 24, 2008 Author Share Posted January 24, 2008 The way I check for an internet connection isIf Ping('google.co.uk') > 0 Then;if I can see google then I have a connection. (Any url which is unlikely to disappear, maybe try 2 or 3 to be sure.)Look up ShutDown in the help.To restart running processes might be a little tricky if they don't start automatically. The ones you definitely need to run you can either either put in your startup folder or just get your script to Run them or ShellExecute them, but if they need some sort of interaction to get started you will have a bit more scripting to do.It might be worth trying to disable your Ethernet port and then anable it again to see if that works instead of rebooting..I tried the ping and it works, sadly i have many dropouts on my internet connection - adsl 8 mbit so just one dropout is enough to restart the pc. Is there any way to try the ping for example 10 times and if there then isn't any internet connection after 10 times restart the pc? How do i code this? Link to comment Share on other sites More sharing options...
martin Posted January 24, 2008 Share Posted January 24, 2008 I tried the ping and it works, sadly i have many dropouts on my internet connection - adsl 8 mbit so just one dropout is enough to restart the pc. Is there any way to try the ping for example 10 times and if there then isn't any internet connection after 10 times restart the pc? How do i code this? You could use AdlibEnable like this (not tested) AdlibEnable("checkConnection",2000);check every 2 seconds Global $TimeDown = 0; Global $DownLongTime = false Const $MaxTimeDown = 5*60*1000 while 1 if $DownLongTime then MsgBox(0,'down','for more than 5 minutes') Sleep(1000) WEnd Func checkConnection() Local $con if Ping('google.co.uk') > 0 Then $Timedown = 0 $DownLongTime = false Else ;if not already done, record the time if $Timedown = 0 then $TimeDown = TimerInit() ;$DownLOngTime = False Else ;if down for more than 5 min then reboot ;if TimerDiff($Timedown) > $MaxTimeDown Then Shutdown(6) if TimerDiff($Timedown) > $MaxTimeDown Then $DownLongTime = true EndIf EndIf Endfunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jorgeng Posted January 25, 2008 Author Share Posted January 25, 2008 (edited) You could use AdlibEnable like this (not tested) AdlibEnable("checkConnection",2000);check every 2 seconds Global $TimeDown = 0; Global $DownLongTime = false Const $MaxTimeDown = 5*60*1000 while 1 if $DownLongTime then MsgBox(0,'down','for more than 5 minutes') Sleep(1000) WEnd Func checkConnection() Local $con if Ping('google.co.uk') > 0 Then $Timedown = 0 $DownLongTime = false Else ;if not already done, record the time if $Timedown = 0 then $TimeDown = TimerInit() ;$DownLOngTime = False Else ;if down for more than 5 min then reboot ;if TimerDiff($Timedown) > $MaxTimeDown Then Shutdown(6) if TimerDiff($Timedown) > $MaxTimeDown Then $DownLongTime = true EndIf EndIf Endfunc Hello again. I tried script, goes ok first 15 minutes, then it restart the pc but internet is still up and running, so there is something in code which is not working. What? Edited January 25, 2008 by jorgeng Link to comment Share on other sites More sharing options...
jorgeng Posted January 27, 2008 Author Share Posted January 27, 2008 Hello again.I tried script, goes ok first 15 minutes, then it restart the pc but internet is still up and running, so there is something in code which is not working. What? Can someone check the code please, it doesn't work.Thanks Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 27, 2008 Share Posted January 27, 2008 (edited) jorgeng - This is more reliable than the Ping method, but I haven't thoroughly tested it: expandcollapse popup#NoTrayIcon ; Checks for a connection every five minutes, if one is not found, ; the program waits five minutes, checks again and if still no ; connection, it keeps attempting reboot until successful. ; Writes a shortcut to itself in the user's startup folder, ; if not there already. #Include <Constants.au3> #include <INet.au3> Opt("TrayMenuMode", 1); Default tray menu items will not be shown. TraySetIcon("Shell32.dll", -44) Global Const $TakeFive = 5 * 60 * 1000 Global Const $exit_item = TrayCreateItem("Exit") Global Const $startup_Link = @StartupDir & "\" & @ScriptName & ".lnk" Global $ShutdownSuccessful Global $pageThere Global $dataFound Global $TrayMsg If Not FileExists($startup_Link) Then FileCreateShortcut(@ScriptFullPath, $startup_Link) EndIf Check_Connect() AdlibEnable("Check_Connect", $TakeFive) TraySetState() TraySetToolTip("Connection Checker" & @CR & " This might reboot your machine.") While 1 $TrayMsg = TrayGetMsg() If $TrayMsg = $exit_item Then ExitLoop EndIf Sleep(80) WEnd Func Check_Connect() $dataFound = _INetGetSource("www.google.com") Sleep(3000) If StringLen($dataFound) < 100 Then Sleep($TakeFive) $pageThere = _INetGetSource("www.google.com") Sleep(3000) If StringLen($pageThere) < 100 Then Do Sleep(20000) $ShutdownSuccessful = Shutdown(2) Until $ShutdownSuccessful EndIf EndIf EndFunc Edited January 27, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
martin Posted January 27, 2008 Share Posted January 27, 2008 Can someone check the code please, it doesn't work. ThanksI'm not really the best person to answer since it's my code. I checked it with this AdlibEnable("checkConnection", 2000);check every 2 seconds Global $TimeDown = 0; Global $DownLongTime = False Const $MaxTimeDown = 5 * 60 * 1000 Global $lostCon = 0 While 1 If $DownLongTime Then MsgBox(0, 'down', 'for more than 5 minutes') Sleep(1000) WEnd Func checkConnection() Local $con If Ping('google.com') > 0 Then $TimeDown = 0 $DownLongTime = False ToolTip("Internet connection is OK. Lost connection " & $LostCon & " times.", 0, 0) Else $LostCon += 1 ;if not already done, record the time If $TimeDown = 0 Then $TimeDown = TimerInit() ;$DownLOngTime = False Else ;if down for more than 5 min then reboot ;if TimerDiff($Timedown) > $MaxTimeDown Then Shutdown(6) ToolTip("No connection for " & Int(TimerDiff($TimeDown) / 1000) & ' seconds!', 0, 0) If TimerDiff($TimeDown) > $MaxTimeDown Then $DownLongTime = True EndIf EndIf EndFunc ;==>checkConnection I disabled my network connection and the time counted up as expected. I enabled the connection and the message is connection ok. I'll leave it on overnight and let you know what happens. The problem might be due the the 2 seconds repeat. Suppose there is a delay every now and then with the response to the ping. The timeout defaults to 4 seconds, so the ping instructions could hang waiting for a response for more than 2 seconds, meanwhile the function is called again and from then on it will always fail. So my guess is that the solution is to change the adlib to fire at more than 4 second intervals. Try 10 seconds. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted January 28, 2008 Share Posted January 28, 2008 jorgeng - This is more reliable than the Ping method, but I haven't thoroughly tested it: expandcollapse popup#NoTrayIcon ; Checks for a connection every five minutes, if one is not found, ; the program waits five minutes, checks again and if still no ; connection, it keeps attempting reboot until successful. ; Writes a shortcut to itself in the user's startup folder, ; if not there already. #Include <Constants.au3> #include <INet.au3> Opt("TrayMenuMode", 1); Default tray menu items will not be shown. TraySetIcon("Shell32.dll", -44) Global Const $TakeFive = 5 * 60 * 1000 Global Const $exit_item = TrayCreateItem("Exit") Global Const $startup_Link = @StartupDir & "\" & @ScriptName & ".lnk" Global $ShutdownSuccessful Global $pageThere Global $dataFound Global $TrayMsg If Not FileExists($startup_Link) Then FileCreateShortcut(@ScriptFullPath, $startup_Link) EndIf Check_Connect() AdlibEnable("Check_Connect", $TakeFive) TraySetState() TraySetToolTip("Connection Checker" & @CR & " This might reboot your machine.") While 1 $TrayMsg = TrayGetMsg() If $TrayMsg = $exit_item Then ExitLoop EndIf Sleep(80) WEnd Func Check_Connect() $dataFound = _INetGetSource("www.google.com") Sleep(3000) If StringLen($dataFound) < 100 Then Sleep($TakeFive) $pageThere = _INetGetSource("www.google.com") Sleep(3000) If StringLen($pageThere) < 100 Then Do Sleep(20000) $ShutdownSuccessful = Shutdown(2) Until $ShutdownSuccessful EndIf EndIf EndFunc What do you think is unreliable about my method Squirrely1? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 28, 2008 Share Posted January 28, 2008 (edited) What do you think is unreliable about my method Squirrely1? jorgeng complained about Ping not being reliable and I have had some apparent problems with it myself. I also have been using INetGet and had problems, but I read on the forums that the UDF _INetGetSource might be more reliable. But I don't know for sure. If the string returned by _INetGetSource is stored in a variable, and the file being downloaded is very large, there might even be problems with it. But jorgeng might have big money depending on this because he is trading stock. @jorgeng - You should know that there are apparently two normal ways to get your internet connection to reconnect if the line is dropped: Start Menu > Network Connections > right-click your default connection > Options tab Start Menu > Control Panel > Internet Options > Settings button > Advanced button Edited January 28, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
jorgeng Posted January 29, 2008 Author Share Posted January 29, 2008 What do you think is unreliable about my method Squirrely1? jorgeng complained about Ping not being reliable and I have had some apparent problems with it myself. I also have been using INetGet and had problems, but I read on the forums that the UDF _INetGetSource might be more reliable. But I don't know for sure. If the string returned by _INetGetSource is stored in a variable, and the file being downloaded is very large, there might even be problems with it. But jorgeng might have big money depending on this because he is trading stock. @jorgeng - You should know that there are apparently two normal ways to get your internet connection to reconnect if the line is dropped: Martin, i changed checkconnection from 2000 to 10000 and now it works. I also had to do a delay for 24000 in the start of script because my computer with vista is quite slow in startup - takes about 5 minutes to start. Thanks squireely1 too, if i get problems i will check your solution. Regards Jorgen 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