How to ping a network using VBScript

You can ping a network using VBScript. Yes, you read it right. We don’t know how many times we must have the necessity to ping a given network but, in order to do that, you have to open a command prompt and do that.

VBScript works so well with the windows system that you can do almost anything. The only limitation is your knowledge. Here we will see how to ping a network using VBScript.

Example code to ping a network using vbscript
Function Ping_Network(sHost)
'This function checks that you can get through to the host you require
'Example usage:
' 'Check we have internet...
' If Not Ping_Network("") Then
' Msgbox "Not connected to Internet",vbCritical,"Fatal Error:"
' Call ExitTest()
' End If
    msgbox "Gen_Ping : " & sHost
    Dim oPing, oRetStatus
    Set oPing = GetObject("winmgmts:").ExecQuery ("select * from Win32_PingStatus where address = '" & sHost & "'")
    For Each oRetStatus In oPing
        If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
            msgbox "Gen_Ping Failed - Status code :" & oRetStatus.StatusCode
            Ping_Network= False
            msgbox "Gen_Ping OK - Bytes : " & vbTab & oRetStatus.BufferSize
            msgbox "Gen_Ping OK - Time(ms) : " & vbTab & oRetStatus.ResponseTime
            msgbox "Gen_Ping OK - TTL(s) : " & vbTab & oRetStatus.ResponseTimeToLive
            Ping_Network= True
        End If
    Set oPing = Nothing
End Function

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.