Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ping workstation kinda works, but not really

Status
Not open for further replies.

holidayIT

IS-IT--Management
Apr 2, 2004
138
US
I fear this script will never work. I have a script that pushes a file to a list of workstations. i ping the workstation before i copy in order to keep the script from crashing. however, if the ping time out takes too long or expires in transit, the script locks up. it doesn't crash, it just sits there. Does anyone know how i can fix this? here is my code for the ping function:

response = ping(strComputerName)
intSuccess = instr(response," Received = 0")
'wscript.echo intSuccess

if intSuccess = 0 then
' Wscript.Echo "Connected " & strComputerName
blnSeverUp = true
else
blnServerUp = false
' Wscript.Echo "Not Connected " & strComputerName
end if


function ping(strTarget)
'cmdline="%COMSPEC% /c ping " & response
'wscript.Echo strTarget
cmdline="ping " & strTarget
Call ExternalCMDCall(cmdline,strOut)
ping=strOut
'wscript.echo ping
end function

Sub ExternalCMDCall(cmdline,strOut)
set objExCmd = objShell.Exec(cmdline)
strOut=objExCmd.StdOut.ReadAll
End Sub
 
Have you tried just using On Error Resume Next before you try to copy the file? Then you can check the Err.Number to see if the copy worked or not. That way you don't need to ping at all.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello holidayIT,

Just set the timeout for each reply (-w in millisecond). If need more control, set the number of requests to send (-n number, default to 4), such as this:
cmdline = "ping -w 50 -n 2 " & strTarget
or
cmdline = "ping -w 100 -n 8 " & strTarget
etc.
Make your optimal choice.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top