JusGellin Posted February 14, 2008 Share Posted February 14, 2008 I'm trying to access and process files on many network computers as fast as I can. Some of the computers could be offline so I wouldn't complete the processing and immediately go on to the next computer. I tried using the FileExists function but found that if I try to use variables to piece together the computer\path\file that it would take a very long time for it to detect an error for a computer that wasn't on line. I need to be able to use variables so I can loop through all these computers. If I just insert quoted text into the function, it doesn't take any time at all. Below is an example of testing the different conditions using variables and just using text for an offline and an online computer. My question is how can I quickly detect a network computer that is offline and go on to the next computer using variables, so I can loop through these? Also why is it that if I concatenate variables it takes so long to error out compared to just using quoted text? Thanks ;Example 1 - off line computer using variables takes 16 seconds $begin = TimerInit() $computer = "notactive" $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 1 time = " & TimerDiff($begin) & @CRLF) ;Example 2 - off line computer using text string takes .29 seconds $begin = TimerInit() FileExists("\\notactive\c$\windows\notepad.exe") ConsoleWrite("Example 2 time = " & TimerDiff($begin) & @CRLF) ;Example 3 - on line computer using variables takes 2.42 seconds $begin = TimerInit() $computer = "AS2007" ; set to actual computer $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 3 time = " & TimerDiff($begin) & @CRLF) ;Example 4 - on line computer using text string takes .58 seconds $begin = TimerInit() FileExists("\\AS2007\c$\windows\notepad.exe"); set to actual computer ConsoleWrite("Example 4 time = " & TimerDiff($begin) & @CRLF) Link to comment Share on other sites More sharing options...
JusGellin Posted February 14, 2008 Author Share Posted February 14, 2008 I tried pinging and the time is worse. expandcollapse popup;Example 1 - off line computer using variables takes 16 seconds $begin = TimerInit() $computer = "nonexistant" $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 1 time = " & TimerDiff($begin) & @CRLF) ;Example 2 - off line computer using text string takes .29 seconds $begin = TimerInit() FileExists("\\nonexistant\c$\windows\notepad.exe") ConsoleWrite("Example 2 time = " & TimerDiff($begin) & @CRLF) ;Example 3 - on line computer using variables takes 2.42 seconds $begin = TimerInit() $computer = "AS2007" ; set to actual computer $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 3 time = " & TimerDiff($begin) & @CRLF) ;Example 4 - on line computer using text string takes .58 seconds $begin = TimerInit() FileExists("\\AS2007\c$\windows\notepad.exe"); set to actual computer ConsoleWrite("Example 4 time = " & TimerDiff($begin) & @CRLF) ;Example 5 - ping off line computer takes 23 seconds $begin = TimerInit() $computer = "nonexistent" ; set to actual computer $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" ping($computer,1) ConsoleWrite("Example 5 time = " & TimerDiff($begin) & @CRLF) ;Example 6- ping on line computer takes 3.36 seconds $begin = TimerInit() $computer = "AS2007" ; set to actual computer $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" ping($computer) ConsoleWrite("Example 6 time = " & TimerDiff($begin) & @CRLF) Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 14, 2008 Share Posted February 14, 2008 Your test is invalid. The second check of the same computer name is only faster because the previous lookup (or failure) was cached. Run it this way to compare: ;Example 2 - off line computer using text string takes .29 seconds $begin = TimerInit() FileExists("\\notactive\c$\windows\notepad.exe") ConsoleWrite("Example 2 time = " & TimerDiff($begin) & @CRLF) ;Example 1 - off line computer using variables takes 16 seconds $begin = TimerInit() $computer = "notactive" $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 1 time = " & TimerDiff($begin) & @CRLF) ;Example 4 - on line computer using text string takes .58 seconds $begin = TimerInit() FileExists("\\AS2007\c$\windows\notepad.exe"); set to actual computer ConsoleWrite("Example 4 time = " & TimerDiff($begin) & @CRLF) ;Example 3 - on line computer using variables takes 2.42 seconds $begin = TimerInit() $computer = "AS2007" ; set to actual computer $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 3 time = " & TimerDiff($begin) & @CRLF) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JusGellin Posted February 14, 2008 Author Share Posted February 14, 2008 Yep, thanks for helping me see the caching part occurring. Wow, that sure takes a long time. Using ping was worse though. Your test is invalid. The second check of the same computer name is only faster because the previous lookup (or failure) was cached. Run it this way to compare: ;Example 2 - off line computer using text string takes .29 seconds $begin = TimerInit() FileExists("\\notactive\c$\windows\notepad.exe") ConsoleWrite("Example 2 time = " & TimerDiff($begin) & @CRLF) ;Example 1 - off line computer using variables takes 16 seconds $begin = TimerInit() $computer = "notactive" $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 1 time = " & TimerDiff($begin) & @CRLF) ;Example 4 - on line computer using text string takes .58 seconds $begin = TimerInit() FileExists("\\AS2007\c$\windows\notepad.exe"); set to actual computer ConsoleWrite("Example 4 time = " & TimerDiff($begin) & @CRLF) ;Example 3 - on line computer using variables takes 2.42 seconds $begin = TimerInit() $computer = "AS2007" ; set to actual computer $path = "c$\windows\" $File = "\\" & $computer & "\" & $path & "notepad.exe" FileExists($File) ConsoleWrite("Example 3 time = " & TimerDiff($begin) & @CRLF) Link to comment Share on other sites More sharing options...
CodeMaster Rapture Posted February 15, 2008 Share Posted February 15, 2008 The only way I could suggest doing this is by setting up a TCP server and client (copy client onto every PC on your network) and have all the PCs connect to the server and do a keep alive. The server PC would have a list of all PCs on the network and there would be no "lag" to speak of. This is alot of work for something so simple though. -CMR Link to comment Share on other sites More sharing options...
boomingranny Posted February 15, 2008 Share Posted February 15, 2008 (edited) I am a bit confused as to why it is taking over 3 seconds to ping an online/offline computer. When you ping from a dos prompt does it take the same time? I would do it as below, but this won't work for you if you are indeed having really bad pings... (which isn't normal on a Local Area Network) Const $PingTimeout = 1000;1 second test ("danserve", "data") Exit Func Test ($Server, $Share) $var = Ping($server,$PingTimeout) If $var Then ;online ShellExecute ("Explorer", "\\" & $server & "\" & $share) Else ;offline or other error EndIf EndFunc i have tried pinging an offline computer using the autoit ping command and it times out straight away Edited February 15, 2008 by boomingranny Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 15, 2008 Share Posted February 15, 2008 I am a bit confused as to why it is taking over 3 seconds to ping an online/offline computer. When you ping from a dos prompt does it take the same time? I would do it as below, but this won't work for you if you are indeed having really bad pings... (which isn't normal on a Local Area Network) i have tried pinging an offline computer using the autoit ping command and it times out straight away You are confusing timeout on the ping (ICMP Echo) with timeout on address resolution. If you ping a computer name, there is a name resolution process that must be completed before any actual pings can be done. If the name doesn't exist, then the failed resolution has to fall through all the various types (hosts file, DNS server(s), WINS server(s), LMHosts file, NetBIOS broadcasts, etc.) before the ping command finally fails. When you ping an IP address that doesn't exist, then there is no name resolution, only ARP, and the timeout can be specified as short as desired in the command line, as well as a parameter to only try once: PING 192.168.1.123 /n 1 /w 50 This will make only one attempt with a timeout at 50ms. Too short to ping things on a WAN link, but appropriate for LAN ports. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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