Break on
If Ping("printerserver", 0) <> 0
$rc = AddPrinterConnection("\\printserver\printer")
EndIf
;FUNCTION Ping()
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
;
;VERSION HISTORY 1.0 - 11/24/2001 Initial Release
; 1.1 - 11/11/2004 Fixed problems regarding spaces in folder names
; of script directory (thanks to Alistair)
; 1.2 - 12/07/2004 Fixed for NoVarsInStrings and Explicit on
;
;ACTION Pings the Computer specified, or returns its ip address (Wins Resolved)
;
;SYNTAX Ping(Computer,GetIP,[LoopCount],[Timeout])
;
;PARAMETERS Computer (Required)
; - String value representing the Computer to ping
;
; GetIp (Required)
; - If specified (1), the function will return the ip-address
; of specified Computer rather than pinging it ...
; Has to be 0 if you want to check for reply !
;
; LoopCount (Optional but useful !)
; - Integer value representing the number of times
; the Computer shall be pinged
;
; Timeout (Optional)
; - if ommited the Computer gets pinged with the default
; timeout (1s) and default retries (4)
;
;REMARKS If there is a reply the function will return immediately with 1
; so it could be faster not specifiying a timeout.
;
;RETURNS 0 - No reply
; 1 - Ping reply
; Optional - ip address of specified Computer
;
;DEPENDENCIES None
;
;EXAMPLES call "path\Ping.udf"
; if Ping("www.microsoft.com",0,12,5000) ;pings for max. 60 seconds
; run "%ComSpec% /c start www.microsoft.com"
; else
; 'Site isn't available ' ?
; endif
; if Ping("www.microsoft.com",0,15) ;pings also for max. 60 seconds
; run "%ComSpec% /c start www.microsoft.com"
; else
; 'Site isn't available ' ?
; endif
; $ip = Ping("www.microsoft.com",1)
; $ip ?
Function Ping($Computer, $GetIP, optional $LoopCount, optional $TimeOut)
If $GetIP
Dim $ip, $ipfile, $
$ipfile = @scriptdir + '\ip.txt'
Shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN (' + Chr(39)
+ '"ping ' + $Computer + ' -n 1 | find "]""' + Chr(39) + ') do echo %%i >"' + $ipfile + '"'
$ = Open(10, $ipfile, 2) $ip = ReadLine(10) $ = Close(10) Del $ipfile
If $ip
$Ping = $ip
Else
$Ping = 'Bad IP address ' + $Computer + '!'
EndIf
Exit 0
Else
If $TimeOut
For $c = 0 to $LoopCount
Shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
If @error = 0
$Ping = 1
Exit 0
EndIf
Next
Else
For $c = 0 to $LoopCount
Shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
If @error = 0
$Ping = 1
Exit 0
EndIf
Next
EndIf
$Ping = 0
EndIf
EndFunction