TheBlackBeltPanda Posted July 17, 2012 Share Posted July 17, 2012 (edited) Hi, I'm trying to write a script that does the following: Checks every 10 seconds for an internet connection by pinging Google.com If no internet connection exists, closes easytthr.exe and re-opens it However, when I run the program, it does nothing but constantly open new instances of easytthr.exe. Can someone tell me what I screwed up? Thanks Code: Local $keepLoop = 1 Local $isConnected = Ping ( "http://www.google.com" ) While $keepLoop While $isConnected Sleep ( 10000 ) WEnd ProcessClose ( "easytthr.exe *32" ) Run ( "C:Program Files (x86)Mobile StreamEasyTethereasytthr.exe" ) WEnd Edited July 17, 2012 by TheBlackBeltPanda Link to comment Share on other sites More sharing options...
TheBlackBeltPanda Posted July 17, 2012 Author Share Posted July 17, 2012 Nevermind, I see the problem staring me in the face. Now where's that darn delete button... Link to comment Share on other sites More sharing options...
darkshark Posted July 18, 2012 Share Posted July 18, 2012 (edited) Local $isConnected = Ping ("http://www.google.com") While 1 While $isConnected Sleep (10000) $isConnected = Ping ("http://www.google.com") WEnd ProcessClose("easytthr.exe *32" ) Run ("C:Program Files (x86)Mobile StreamEasyTethereasytthr.exe") WEnd Edited July 18, 2012 by darkshark Link to comment Share on other sites More sharing options...
TheBlackBeltPanda Posted July 18, 2012 Author Share Posted July 18, 2012 (edited) Ping wasn't working for me so I did some searching, found a way to check network connection status, and managed to get it working. This is what worked for me:expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Array.au3> TraySetToolTip("EasyTether Connection Checker") Global $aArray Local $iIndex While 1 Sleep (10000) $aArray = _AdapterConnections() ; Data is returned as a 2D Array. Adapter|Status. $iIndex = _ArraySearch($aArray, "EasyTether Network Adapter", 0, 0, 0, 1, 1, 0) If $aArray[$iIndex][1] == "Media disconnected" Then ProcessClose("easytthr.exe" ) Run ("C:Program Files (x86)Mobile StreamEasyTethereasytthr.exe") EndIf WEnd Func _AdapterConnections($sComputer = @ComputerName) Local $aReturn[1][2] = [[0, 2]], $iDimension = 0, $oColItems, $oWMIService, $sDelimeter = Chr(01), $sReturn = "" Local $aStatus[13] = ["Disconnected", "Connecting", "Connected", "Disconnecting", "Hardware not present", _ "Hardware disabled", "Hardware malfunction", "Media disconnected", "Authenticating", "Authentication succeeded", _ "Authentication failed", "Invalid address", "Credentials required"] $oWMIService = ObjGet("winmgmts:" & $sComputer & "") $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapter", "WQL", 0x30) If IsObj($oColItems) Then For $oObjItem In $oColItems If $oObjItem.AdapterType = "" Or $oObjItem.NetConnectionID = "" Then ; Ensures that the connections are physical adapters. ContinueLoop EndIf If StringInStr($sDelimeter & $sReturn, $sDelimeter & $oObjItem.Description & $sDelimeter, 1) Then ; Ensures there are no duplicates. ContinueLoop EndIf $sReturn &= $oObjItem.Description & $sDelimeter If ($aReturn[0][0] + 1) >= $iDimension Then ; http://www.autoitscript.com/forum/topic/129689-redim-the-most-efficient-way-so-far-when-you-have-to-resize-an-existing-array/ $iDimension = ($aReturn[0][0] + 1) * 2 ReDim $aReturn[$iDimension][$aReturn[0][1]] EndIf $aReturn[0][0] += 1 $aReturn[$aReturn[0][0]][0] = $oObjItem.Description For $A = 0 To 12 If $oObjItem.NetConnectionStatus = $A Then ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx $aReturn[$aReturn[0][0]][1] = $aStatus[$A] ExitLoop EndIf Next Next EndIf ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] $aReturn[0][1] = "" Return $aReturn EndFunc ;==>_AdapterConnections Edited July 18, 2012 by TheBlackBeltPanda Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 18, 2012 Share Posted July 18, 2012 This should work for you as well.. While 1 If Not _IsInternetConnected() Then ;ProcessClose("easytthr.exe *32" ) ;Run ("C:Program Files (x86)Mobile StreamEasyTethereasytthr.exe") MsgBox(0, '', 'no internet') EndIf Sleep(10 * 1000) WEnd Func _IsInternetConnected() ; http://www.autoitscript.com/wiki/AutoIt_Snippets#IsInternetConnected.28.29_.7E_Author_-_guinness Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected') If @error Then Return SetError(1, 0, False) EndIf Return $aReturn[0] = 0 EndFunc ;==>_IsInternetConnected - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. 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