Mingre Posted April 9, 2013 Posted April 9, 2013 (edited) Hello AutoIt community, Is there a workaround for including timeout for these functions? They work great when the networked computers are actually online, but really slow if otherwise. I did a simple test (see below) and learned that there's a function faster (at least for my purpose) than ping(). Credits to guinness for _WinAPI_PathFileExists() (you're the one who posted this code, right?). This also talked about the same problem though it ended with martin's suggesting his UDF. I tried to understand it but unfortunately can't. There's lot of threads relevant to my question but I *sincerely* deemed their discussion too complicated for my level. Please help. Thanks! _testAPI('\\G11\d') _testPing('G11') _testAPI('\\G12\d') _testPing('G12') ConsoleWrite('+++++++++++++++++++++++++++++++++++' & @CRLF) Sleep(2000) _testPing('G11') _testAPI('\\G11\d') _testPing('G12') _testAPI('\\G12\d') Func _testAPI($NetworkComputer) Local $TimeStarts = TimerInit() Local $TestOnline = _WinAPI_PathFileExists($NetworkComputer) ConsoleWrite('API - Online? ' & $TestOnline & ' at ' & TimerDiff($TimeStarts) & 'ms' & @CRLF) EndFunc ;==>_test Func _testPing($NetworkComputer) Local $TimeStarts = TimerInit() Local $TestOnline = Ping($NetworkComputer, 250) ConsoleWrite('Ping - Online? ' & $TestOnline & ' at ' & TimerDiff($TimeStarts) & 'ms' & @CRLF) EndFunc ;==>_test Func _WinAPI_PathFileExists($sFilePath) Local $aReturn = DllCall('shlwapi.dll', 'int', 'PathFileExistsW', 'wstr', $sFilePath) If @error Then Return SetError(1, 0, 0) EndIf Return $aReturn[0] EndFunc ;==>_WinAPI_PathFileExists ** G11 is online; G12 is offline (but is existing) Output: API - Online? 1 at 3.93117268793799ms Ping - Online? 1 at 8.20257552028031ms API - Online? 0 at 6739.93723056912ms Ping - Online? 0 at 2249.59833463846ms +++++++++++++++++++++++++++++++++++ Ping - Online? 1 at 0.782496947334891ms API - Online? 1 at 0.680369040666808ms Ping - Online? 0 at 2248.8030350791ms API - Online? 0 at 6711.45924658898ms Edit: Some grammar lapses Edit 2: Changed output from 'autoit' to 'quote' Edited April 10, 2013 by Mingre
Mingre Posted April 10, 2013 Author Posted April 10, 2013 (edited) Hello again, I just stumbled into a code I had copied before from the site, which is prolly good enough for my mini-project. Here's it:_list() Func _list() Local $foo, $sActiveLine, $line $foo = Run(@ComSpec & " /c net view ", @SystemDir, @SW_HIDE, 2) While 1 $sActiveLine = StdoutRead($foo) If @error Then ExitLoop If StringLeft($sActiveLine, 2) = "\\" Then $line &= StringReplace($sActiveLine, "\\", "") & @CRLF EndIf WEnd $line = StringReplace($line, " ", "") $line = StringReplace($line, @LF, "") $line = StringSplit($line, @CR) TCPStartup() For $i = 1 To $line[0] - 1 $result = Ping($line[$i], 1) If Not @error Then ConsoleWrite('>ONLINE : ' & $line[$i] & @CRLF) Else ConsoleWrite('+OFFLINE : ' & $line[$i] & @CRLF) EndIf Next EndFunc ;==>_list I apologize to this code's author for not citing you (because I don't know you, sorry!). Edited April 10, 2013 by Mingre
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