Ping a Remote Server Using VBScript

At times you might build a customization in the SalesLogix LAN client that relies on networked resources. For example, you might consume a web service or other resource that is available to LAN users and remote users via VPN. In this scenario, and many others like it, you have the potential to have remote users that do not currently have access to this networked resource. Even worse, you might have remote users that may not even be online at the time. A quick PING can check for availability.

You can perform a PING by executing the PING command-line via the Shell. Here is a reusable function to do just this:

Function Ping(Target)
Dim results

    On Error Resume Next

    Set shell = CreateObject("WScript.Shell")

    ' Send 1 echo request, waiting 2 seconds for result
    Set exec = shell.Exec("ping -n 1 -w 2000 " & Target)
    results = LCase(exec.StdOut.ReadAll)

    Ping = (InStr(results, "reply from") > 0)
End Function

Now to use that code you simply pass the IP address or hostname to the Ping function and check the boolean result

If Ping("192.168.1.100") Then
    ' Do something to access the resource
End If

You can optionally adjust the number of times the ping request is sent and the timeout interval to wait for the result.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Thanks for that. Worked like a charm!

    Reply

Submit a Comment

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

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!