Guys,
I am trying to write a program that will send a ping packet to a server and then read the reply. Depending on whether the reply contains the word "reply" ( as in reply from xxxxxxx)or "request" (as in request timed out) I will then take the appropriate action.
So far I have managed to get some of it to work, whereby I use a select or an IF statement which looks for the word 'reply' and then the script takes the action I want. BUT if I use a second clause to the IF or SELECT statement to check the second condition (ie 'request' in the ping reply) nothing happens.
My script is as follows (I've only included the relevant part)
Sub Pinger
Pinger = False
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject=objShell.Exec("cmd /k ping -n 1 -w 1000" & " " & strComputer)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
Select Case strText
Case 1 Instr(readOut) = "Reply"
Wscript.Echo "Reply received."
Call IEVER
Case 2 Instr(readOut) = "Request"
Call Offline
Wscript.Echo "machine off"
End Select
Loop
End Sub
So to re-cap, the script runs as intended if the machine is online, but if the machine is offline, the script dosent branch off to the second case statement and call the subroutine Offline. Instead it seeems to ignore the second case statement alltogether and just runs the first case statement, thus calling the incorrect sub-routine.
Just to add a little bit more confusion, if I try using an IF...THEN...ELSE statement like in the following the script, it just hangs when it reaches a machine that is offline.
function Pinger
'Pinger = False
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject=objShell.Exec("cmd /k ping -n 1 -w 1000" & " " & strComputer)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received."
Call PingResult
Else
Wscript.Echo "Machine Offline"
Exit Do
End If
Loop
End Function
However if I omit the Else statement in the same script above, things work fine. But of course I am then faced with the problem of not being able to take any action if the machine is offline.
Any help you guys can give would be really great.
I am trying to write a program that will send a ping packet to a server and then read the reply. Depending on whether the reply contains the word "reply" ( as in reply from xxxxxxx)or "request" (as in request timed out) I will then take the appropriate action.
So far I have managed to get some of it to work, whereby I use a select or an IF statement which looks for the word 'reply' and then the script takes the action I want. BUT if I use a second clause to the IF or SELECT statement to check the second condition (ie 'request' in the ping reply) nothing happens.
My script is as follows (I've only included the relevant part)
Sub Pinger
Pinger = False
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject=objShell.Exec("cmd /k ping -n 1 -w 1000" & " " & strComputer)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
Select Case strText
Case 1 Instr(readOut) = "Reply"
Wscript.Echo "Reply received."
Call IEVER
Case 2 Instr(readOut) = "Request"
Call Offline
Wscript.Echo "machine off"
End Select
Loop
End Sub
So to re-cap, the script runs as intended if the machine is online, but if the machine is offline, the script dosent branch off to the second case statement and call the subroutine Offline. Instead it seeems to ignore the second case statement alltogether and just runs the first case statement, thus calling the incorrect sub-routine.
Just to add a little bit more confusion, if I try using an IF...THEN...ELSE statement like in the following the script, it just hangs when it reaches a machine that is offline.
function Pinger
'Pinger = False
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject=objShell.Exec("cmd /k ping -n 1 -w 1000" & " " & strComputer)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received."
Call PingResult
Else
Wscript.Echo "Machine Offline"
Exit Do
End If
Loop
End Function
However if I omit the Else statement in the same script above, things work fine. But of course I am then faced with the problem of not being able to take any action if the machine is offline.
Any help you guys can give would be really great.