Use Win32_PingStatus WMI class
//JScript
var objLocalWMI = GetObject("Winmgmts:");
var enumPingStatus = new Enumerator(objLocalWMI.ExecQuery("Select StatusCode
from Win32_PingStatus Where Address='192.168.1.1'"));
if(enumPingStatus.item().StatusCode == 0)
{
WScript.Echo("It's allright");
WScript.Quit();
}
else
{
WScript.Echo("Host is unreachable");
....
//to do something....
....
}
'VBScript
Set objLocalWMI = GetObject("Winmgmts:")
Set colItems = objLocalWMI.ExecQuery("Select StatusCode from
Win32_PingStatus Where Address='192.168.1.1'",,48)
For Each objItem In colItems
If objItem.StatusCode = 0 Then
WScript.Echo "It's allright"
WScript.Quit
Else
WScript.Echo "Host is unreachable"
...
'to do something
..
End If
Next
"Spin" <> сообщил/сообщила в новостях следующее:
news:...
> Gurus,
>
> I am trying to write a script which will ping a host, and if the remote
> host replies, the script will exit. Any thoughts? This could be either
> batch or VBS.
>
> --
> Spin
|