Is there a way of finding out if a machine is online that is faster
than ping? I've been using the WMI technique rather than the .Run
method.

Regards,
Bruce.

Re: Faster than Ping? by JHP

JHP
Fri Dec 30 10:29:05 CST 2005

Here is a test (run it more then once to get accurate results)
*** Watch for Word Wrap ***
WMI is faster then Shell (Run):

Option Explicit

Dim startTimer, strComputer, objWMIService, colItems, objItem, strMsg,
endTimer, objWSH, rtnPing
Const WindowStyle = 0
Const WaitOnReturn = True

'***WMI***

startTimer = Timer
strComputer = "XXXXXXX"
Set objWMIService = GetObject("Winmgmts:\\" & "." & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus WHERE
address = '" & strComputer & "'")

For Each objItem in colItems
If objItem.StatusCode = 0 Then
strMsg = "Successful"
Exit For
Else
strMsg = "Failed"
End If
Next
Set colItems = Nothing
Set objWMIService = Nothing
endTimer = Timer
WScript.Echo "Computer: " & strComputer & vbCRLF & "PING: " & strMsg &
vbCRLF & "Time: " & endTimer - startTimer

'***Shell (Run)***

startTimer = Timer
Set objWSH = CreateObject("WScript.Shell")
rtnPing = objWSH.Run("PING -n 1 -w 1 " & strComputer, WindowStyle,
WaitOnReturn)

If rtnPing = 0 Then strMsg = "Successful" Else strMsg = "Failed"

Set objWSH = Nothing
endTimer = Timer
WScript.Echo "Computer: " & strComputer & vbCRLF & "PING: " & strMsg &
vbCRLF & "Time: " & endTimer - startTimer

"axtens" <bruce_axtens@yahoo.com.au> wrote in message
news:1135909255.323668.295070@g44g2000cwa.googlegroups.com...
> Is there a way of finding out if a machine is online that is faster
> than ping? I've been using the WMI technique rather than the .Run
> method.
>
> Regards,
> Bruce.
>



Re: Faster than Ping? by JHP

JHP
Fri Dec 30 10:37:29 CST 2005

Actually WMI is only faster if it can contact the computer otherwise Shell
(Run) is faster:

Six of one, a half dozen of the other?

"JHP" <goawayspam@GFY.com> wrote in message
news:uJsFg4VDGHA.2072@TK2MSFTNGP09.phx.gbl...
> Here is a test (run it more then once to get accurate results)
> *** Watch for Word Wrap ***
> WMI is faster then Shell (Run):
>
> Option Explicit
>
> Dim startTimer, strComputer, objWMIService, colItems, objItem, strMsg,
> endTimer, objWSH, rtnPing
> Const WindowStyle = 0
> Const WaitOnReturn = True
>
> '***WMI***
>
> startTimer = Timer
> strComputer = "XXXXXXX"
> Set objWMIService = GetObject("Winmgmts:\\" & "." & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus
> WHERE address = '" & strComputer & "'")
>
> For Each objItem in colItems
> If objItem.StatusCode = 0 Then
> strMsg = "Successful"
> Exit For
> Else
> strMsg = "Failed"
> End If
> Next
> Set colItems = Nothing
> Set objWMIService = Nothing
> endTimer = Timer
> WScript.Echo "Computer: " & strComputer & vbCRLF & "PING: " & strMsg &
> vbCRLF & "Time: " & endTimer - startTimer
>
> '***Shell (Run)***
>
> startTimer = Timer
> Set objWSH = CreateObject("WScript.Shell")
> rtnPing = objWSH.Run("PING -n 1 -w 1 " & strComputer, WindowStyle,
> WaitOnReturn)
>
> If rtnPing = 0 Then strMsg = "Successful" Else strMsg = "Failed"
>
> Set objWSH = Nothing
> endTimer = Timer
> WScript.Echo "Computer: " & strComputer & vbCRLF & "PING: " & strMsg &
> vbCRLF & "Time: " & endTimer - startTimer
>
> "axtens" <bruce_axtens@yahoo.com.au> wrote in message
> news:1135909255.323668.295070@g44g2000cwa.googlegroups.com...
>> Is there a way of finding out if a machine is online that is faster
>> than ping? I've been using the WMI technique rather than the .Run
>> method.
>>
>> Regards,
>> Bruce.
>>
>
>



Re: Faster than Ping? by Al

Al
Fri Dec 30 12:52:24 CST 2005

and, depending on how many separate computers there are that you want to
check, it might be faster to check for all of them at once using the
following command:

NET VIEW | find "\\" >onlinecomputers.txt

This creates a file listing all computers that are currently online
according to the browse master. There is a bit of a latency issue, so it
will miss those that have just been powered on and hit those that have just
been powered off.


/Al


"JHP" <goawayspam@GFY.com> wrote in message
news:uduRM9VDGHA.1676@TK2MSFTNGP09.phx.gbl...
> Actually WMI is only faster if it can contact the computer otherwise Shell
> (Run) is faster:
>
> Six of one, a half dozen of the other?
>
> "JHP" <goawayspam@GFY.com> wrote in message
> news:uJsFg4VDGHA.2072@TK2MSFTNGP09.phx.gbl...
> > Here is a test (run it more then once to get accurate results)
> > *** Watch for Word Wrap ***
> > WMI is faster then Shell (Run):
> >
> > Option Explicit
> >
> > Dim startTimer, strComputer, objWMIService, colItems, objItem, strMsg,
> > endTimer, objWSH, rtnPing
> > Const WindowStyle = 0
> > Const WaitOnReturn = True
> >
> > '***WMI***
> >
> > startTimer = Timer
> > strComputer = "XXXXXXX"
> > Set objWMIService = GetObject("Winmgmts:\\" & "." & "\root\cimv2")
> > Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus
> > WHERE address = '" & strComputer & "'")
> >
> > For Each objItem in colItems
> > If objItem.StatusCode = 0 Then
> > strMsg = "Successful"
> > Exit For
> > Else
> > strMsg = "Failed"
> > End If
> > Next
> > Set colItems = Nothing
> > Set objWMIService = Nothing
> > endTimer = Timer
> > WScript.Echo "Computer: " & strComputer & vbCRLF & "PING: " & strMsg &
> > vbCRLF & "Time: " & endTimer - startTimer
> >
> > '***Shell (Run)***
> >
> > startTimer = Timer
> > Set objWSH = CreateObject("WScript.Shell")
> > rtnPing = objWSH.Run("PING -n 1 -w 1 " & strComputer, WindowStyle,
> > WaitOnReturn)
> >
> > If rtnPing = 0 Then strMsg = "Successful" Else strMsg = "Failed"
> >
> > Set objWSH = Nothing
> > endTimer = Timer
> > WScript.Echo "Computer: " & strComputer & vbCRLF & "PING: " & strMsg &
> > vbCRLF & "Time: " & endTimer - startTimer
> >
> > "axtens" <bruce_axtens@yahoo.com.au> wrote in message
> > news:1135909255.323668.295070@g44g2000cwa.googlegroups.com...
> >> Is there a way of finding out if a machine is online that is faster
> >> than ping? I've been using the WMI technique rather than the .Run
> >> method.
> >>
> >> Regards,
> >> Bruce.
> >>
> >
> >
>
>