Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

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.

What's This?
  
Bookmark and Share

About Ryan Farley

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

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series



Related Content
   Changes in Sublogix Version 1.2
I've pushed version 1.2 of Sublogix to NuGet. There's some changes in how the custom entity templ
Posted on Aug 24, 2011 by Ryan Farley to Ryan Farley's Blog
 
   SalesLogix Group Explorer Updated
The SalesLogix Group Explorer has become a widely used tool for tracking down issues with SalesLogix grou
Posted on Feb 16, 2011 by Ryan Farley to Ryan Farley's Blog
 
   SalesLogix basics - Easy Data access in SalesLogix LAN
In this basics article, I wanted to outline the use of include scripts within the SalesLogix LAN client.
Posted on Jun 22, 2010 by Jason Buss to Jason Buss' Blog
 
   Community Explorer - The Desktop Client for the Sage SalesLogix Community Forums
Ever since Sage released their official SalesLogix community website & forums, I've wanted a bett
Posted on Feb 09, 2010 by Ryan Farley to Ryan Farley's Blog
 
   Account Hierarchy for SalesLogix Web Source Code Has a New Home
The Account Hierarchy for SalesLogix Web module has a new home. I have moved the source to Github to make
Posted on Dec 07, 2009 by Ryan Farley to Ryan Farley's Blog
 
Comments

 

CRM Developer said:

In my last post, I shared some code in VBScript to PING a remote server to check for availability before attempting to use a resource on that remote server. This wouldn't be my blog if I didn't also share this code in C# as well. IMO, this sort

May 21, 2008 11:37 PM
 

Surendra said:

Hi..

this is a good solution.

Can u plz. help me in vbscript (I want to create a rdp session using vbscript and want its object so that i can disconnect from it or i can read some reg. key on that machine)

June 9, 2008 10:09 AM
 

Ryan Farley said:

Hello Surendra,

You should try a VBScript forum for the help you need. A Google search reveals plenty.

Good luck.

-Ryan

June 9, 2008 10:32 AM
 

Ratna said:

Thanks for tutorial, may I ask your help,..

how to download any file silently using VBScript,....

Thanks in advance

July 25, 2008 12:53 PM
 

bijith said:

Hi All,

I created a VB script for checking the different status of a windows command. For all return codes I made different messages.But if that windows command is not giving responds means no returncode then how will check the status in Vb script? Can we use timer means after a paricular time I want to exit that command?

August 8, 2008 8:08 AM
 

bijith said:

Please let me know, if anybody have this idea for fixing timer for a windows command !!!

August 8, 2008 8:11 AM
 

Ryan Farley said:

Surendra/Ratna/bijith,

Please use a VBScript forum for your questions. Thanks.

-Ryan

August 8, 2008 12:13 PM
 

Bala said:

Hi,

USe this code...

Itmay helpful for you

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colPingedComputers = objWMIService.ExecQuery _

   ("Select * from Win32_PingStatus Where Address = '192.168.1.37'")

For each objComputer in colPingedComputers

   If objComputer.StatusCode = 0 Then

       Wscript.Echo "Remote computer responded."

   Else

       Wscript.Echo "Remote computer did not respond."

  End If

Next

January 20, 2009 1:04 AM
 

Todd Hardin said:

Slick technique using the "exec.StdOut.ReadAll" - I had not seen that before. Nice job Ryan.

April 2, 2009 4:11 AM
 

Travis said:

Whilst it is a nice simple approach, I am getting a quick flash of the cmd window whenever the function is called.  

November 14, 2010 6:39 AM
 

FieryTink said:

Thanks for that. Worked like a charm!

July 15, 2014 8:44 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register