Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

November 14, 2005 12:00 AM

How can I use a VBScript script to ping a machine?

Windows IT Pro
InstantDoc ID #48449
Rating: (19)

A. The Windows Management Instrumentation (WMI) classes in Windows XP and later provide a Win32_PingStatus object that you can use to ping a machine. The following script, which you can download at http://www.windowsitpro.com/content/content/48449/vbpinging.zip uses this object to ping a passed hostname or IP address. Because of space constraints, some lines wrap to two lines.


Option Explicit

Dim strHost

' Check that all arguments required have been passed.
If Wscript.Arguments.Count 0 then
    Ping = False
            'WScript.Echo "Status code is " & objRetStatus.StatusCode
        else
            Ping = True
            'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
            'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
            'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
        end if
    next
End Function 

You can modify this script to do whatever you need. Notice that I've commented out some lines (') that give more information about the ping attempt, but you can leave the lines in if the information would be useful to you. Run the script by using the following command:

D:\projects\VBScripts>cscript vbping.vbs savdalex01
which will give the following sample output:

Host savdalex01 contacted

You can find more information about Win32_PingStatus at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_pingstatus.asp .

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.