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.

ping a network using vbscript

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("www.google.com") 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
            
        Else
            
            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
        
    Next
    
    Set oPing = Nothing
    
End Function

You may also read

ping a network using vbscript

Discover more from Automation Script

Subscribe to get the latest posts sent to your email.

Related Posts