I have a Macro that engages with the Shell to run ping commands, the only problem is that it opens a new command prompt window every time it loops, it's alright if it's only a dozen, but i'm thinking of scaling this up to 1000+
Is there anyway of keeping the one window open and still be able to use the StdOut
Here's my code:
It returns No if it won't ping and returns the i.p. address if it does. I've utilised the collective wisdom of the board on this one so please feel free to use the code.
Function WillItPing(PCToPing As String)
Pings = 1
timeout = 200
Status = CreateObject("WScript.Shell"). _
Exec("%comspec% /c Ping -n " & Pings & " -l 2" & " -w " & timeout & " " & PCToPing).StdOut.ReadAll
If InStr(Status, "TTL=") = 0 Then
'If no ping, return No
WillItPing = "No"
Else
'If it pings, get the I.P. Address
ip_start = InStr(1, Status, "Reply from ", vbTextCompare) + 11
ip_end = InStr(ip_start, Status, ":", vbTextCompare)
Ip_Length = ip_end - ip_start
WillItPing = Mid(Status, ip_start, Ip_Length)
End If
End Function
Is there anyway of keeping the one window open and still be able to use the StdOut
Here's my code:
It returns No if it won't ping and returns the i.p. address if it does. I've utilised the collective wisdom of the board on this one so please feel free to use the code.
Function WillItPing(PCToPing As String)
Pings = 1
timeout = 200
Status = CreateObject("WScript.Shell"). _
Exec("%comspec% /c Ping -n " & Pings & " -l 2" & " -w " & timeout & " " & PCToPing).StdOut.ReadAll
If InStr(Status, "TTL=") = 0 Then
'If no ping, return No
WillItPing = "No"
Else
'If it pings, get the I.P. Address
ip_start = InStr(1, Status, "Reply from ", vbTextCompare) + 11
ip_end = InStr(ip_start, Status, ":", vbTextCompare)
Ip_Length = ip_end - ip_start
WillItPing = Mid(Status, ip_start, Ip_Length)
End If
End Function