Awesum Stuff

How to Read Command Line Output with VBScript ?

We can read the output of a command which is executed on the command prompt with VBS. As an application of this concept, I used it to find out the IP address of a website and check whether its down or not :-


strTarget = “”
Set objShell = CreateObject(“WScript.Shell”)
Set objExec = objShell.Exec(“ping -n 2 ” & strTarget)
blank = LCase(objExec.StdOut.ReadLine)
strPingResults = LCase(objExec.StdOut.ReadAll)
split1 = split(strPingResults)
tempIP = split1(2)
ipAddress= mid(tempIP,2,(len(tempIP)-2))

Set objRegEx = CreateObject(“VBScript.RegExp”)

objRegEx.Global = True
objRegEx.Pattern = “\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}”

Set colMatches = objRegEx.Execute(ipAddress)

If colMatches.Count > 0 Then
msgbox ipAddress
msgbox “Failed”
End If

If Instr(1,strPingResults,”0% loss”,1)>0 Then
msgbox “Website is Up”
msgbox “Website is down”
End If



Categories: Awesum Stuff

Tagged as: , , , , , ,

2 replies »

  1. Hey Harshit ,
    In the Script, we are communicating with QC to update the Test results each time a Test case runs .
    So my requirement is to find out the QC – URL which is dynamic and keeps on changing.

    Can you suggest something that can help me find this URL (maybe in the hidden mode) without having the script to follow the conventional approach of opening IE and entering “http:qc ” and then once the dynamic URL comes in , and using the get URL property to find the URL .

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s