If you looked at yesterday’s post, carefully I’ll admit as WordPress loves to mangle the display of
<CODE>; you might have noticed that I check to see if a computer is on the network, before I try and do something to it.
The reason is simple.
Checking that a computer is on the network, is faster, than just trying to copy a file to it, and checking for a failure. I don’t know why, but I suspect a “Ping” is faster than a file operation.
Here is some (crude) code I wrote the other day, which shows a ping in use:
Set objFSO = CreateObject("Scripting.FileSystemObject")
If not objFSO.FileExists("C:\computer_lists\file_targets.txt") Then
Set ObjStream = objFSO.OpenTextFile("C:\computer_lists\file_targets.txt",1)
file_destination = ""
Do While Not ObjStream.AtEndOfStream
strComputer = ObjStream.ReadLine
If strComputer = "" Then
If Reachable(strComputer) Then
file_destination = "\\" + strComputer + "\c$\pluckaduck\raffle.exe"
On Error Resume Next
If Err.Number <> 0 Then
WScript.echo strComputer + " - failed copy"
On Error GoTo 0
WScript.Echo "Computer is Unreachable!"
' On Error Resume Next
Dim wmiQuery, objWMIService, objPing, objStatus
wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)
For Each objStatus In objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
Reachable = False 'if computer is unreacable, return false
Reachable = True 'if computer is reachable, return true