Submitted By: Frank Methorst

Sample function that pings a device on the network and then returns a value of True or False indicating whether the ping succeeded.

Visual Basic
Edit|Remove
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.0
'
' NAME: Function - Ping.vbs
'
' CREATED       : 4/22/2004
' CREATED BY    : Frank Methorst
' MODIFIED      : 6/8/2004
' MODIFIED BY   : Frank Methorst
'
'
' COMMENT: 
'
'
'==========================================================================
'
' Variable Prefix Standards:
'
' Single letter lower case prefixes should be used
' to identify the type of variable
'
' s = String        (i.e. sComputer, sUser, sDomain etc.)
' o = Object        (i.e. oFSO, oShell, oNetwork, oWMI etc.)
' a = Array         (i.e. aHotfixes, aBranches, etc.)
' c = Collection    (i.e. cComputers, cUsers, cOUs etc.)
' i = Integer       (i.e. i, iNumber, etc.)
' d = Date/Time     (i.e. dDate, dStartTime, dToday etc.)
' b = Boolean       (i.e. bAnswer, bOutput etc.)
' e = Error         (i.e. eNumber, eDescription etc.)
' vb = builtin      (i.e. vbCRLF, vbTAB, vbLongDate etc.)
'
'
' Constant Standards:
' 
' Constants should be identified by using upper case letters
' exclusively separated by underscores:
'
' i.e. OVERWRITE_EXISTING, FILE_SHARE, MAXIMUM_CONNECTIONS etc.
'
'
'==========================================================================

'=================== Script Initialization ================================

Option Explicit
On Error Resume Next

'=================== Constant / Variable Declaration ======================

Dim sComputer


'=================== Object Creation ======================================




'=================== Main Logic ===========================================

' Sample usage

sComputer = "VCRIS"

Msgbox Ping(sComputer)

'=================== Cleanup ==============================================




'=================== Functions / Subroutines ==============================

Function Ping(sComputer)
	On Error Resume Next 
	Dim oWMI
	Dim cPing
	Dim oPing
	Set oWMI = GetObject("winMgmts:")
	Set cPing = oWMI.ExecQuery("Select * from Win32_PingStatus Where Address = " & _
		"'" & sComputer & "'")
	For Each oPing In cPing
		If oPing.StatusCode = 0 Then
			Ping = True
		Else
			Ping = False
		End If
	Next 
	Set oWMI = Nothing
	Set cPing = Nothing
	Set oPing = Nothing
End Function