VBScript Scripting Techniques > Network > Ping

Ping Computers

 

Win32_PingStatus
VBScript Code:
WScript.Echo "www.robvanderwoude.com on-line: " & Ping( "www.robvanderwoude.com" )

Function Ping( myHostName )
' This function returns True if the specified host could be pinged.
' myHostName can be a computer name or IP address.
' The Win32_PingStatus class used in this function requires Windows XP or later.
' This function is based on the TestPing function in a sample script by Don Jones
' http://www.scriptinganswers.com/vault/computer%20management/default.asp#activedirectoryquickworkstationinventorytxt

    ' Standard housekeeping
    Dim colPingResults, objPingResult, strQuery

    ' Define the WMI query
    strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & myHostName & "'"

    ' Run the WMI query
    Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery )

    ' Translate the query results to either True or False
    For Each objPingResult In colPingResults
        If Not IsObject( objPingResult ) Then
            Ping = False
        ElseIf objPingResult.StatusCode = 0 Then
            Ping = True
        Else
            Ping = False
        End If
    Next

    Set colPingResults = Nothing
End Function
Requirements:
Windows version: XP, Server 2003, or Vista
Network: TCP/IP
Client software: N/A
Script Engine: any
Summarized: Works in Windows XP or later.
Doesn't work in Windows 95, 98, ME, NT 4 or 2000.
 
[Back to the top of this page]
 
System Scripting Runtime
VBScript Code:
WScript.Echo "www.robvanderwoude.com on-line: " & PingSSR( "www.robvanderwoude.com" )

Function PingSSR( myHostName )
' This function returns True if the specified host could be pinged.
' myHostName can be a computer name or IP address.
' This function requires the System Scripting Runtime by Franz Krainer
' http://www.netal.com/ssr.htm

    ' Standard housekeeping
    Dim objIP

    Set objIP = CreateObject( "SScripting.IPNetwork" )

    If objIP.Ping( myHostName ) = 0 Then
        PingSSR = True
    Else
        PingSSR = False
    End If

    Set objIP = Nothing
End Function
Requirements:
Windows version: Windows 98, ME, NT 4, 2000, XP, Server 2003 or Vista
Network: TCP/IP
Client software: System Scripting Runtime
Script Engine: any
Summarized: Works in Windows 98 and later with System Scripting Runtime is installed, with any script engine.
 
[Back to the top of this page]

 

 


page last uploaded: 4 March 2011, 12:56