---snip
set objInstance = objService.ExecQuery ("select * from Win32_OperatingSystem
where Primary=true")
for each OS in objinstance
response.write os.name
Next
---snip
If the remote server I'm running this against is down, it takes forever to
reply back an error. I wan the error immediate if the reponse is not given
from the server.
I'm using Win2K, vbscript, and asp
Please help!
Thanks
Brian
Here's a much easier trick; you can ping the remote system using WMI to see if
it will respond before you even try a query; this should speed you up
dramatically. Here's a routine to use WMI's built-in ping provider. You can
use either an IP or a DNS name.
sTarget = "192.168.1.11"
set oPing = _
GetObject("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery ("select * from Win32_PingStatus where address = '" _
& sTarget & "'")
For Each o In oPing
sResp = o.StatusCode : exit for
Next
wscript.echo sResp
if sResp = 0 Then
' do stuff here since it is up
End If
"msnews.microsoft.com" <btu...@hotmail.com> wrote in message
news:epX66oG$BHA.2524@tkmsftngp05...
> Here's a much easier trick; you can ping the remote system using WMI to see if
> it will respond before you even try a query; this should speed you up
> dramatically. Here's a routine to use WMI's built-in ping provider. You can
> use either an IP or a DNS name.
>
> sTarget = "192.168.1.11"
> set oPing = _
> GetObject("winmgmts:{impersonationLevel=impersonate}"). _
> ExecQuery ("select * from Win32_PingStatus where address = '" _
> & sTarget & "'")
Hi
Note that Win32_PingStatus is only available for Windows XP.
--
torgeir
However on the Win32_PingStatus page they had this under Requirements:
Windows NT/2000/XP: Requires Windows NT 4.0 SP4 or later
Namespace: Included in \root\cimv2
MOF: Declared in Ping_desc.mof
Looks like another documentation "bug"...?
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3CE368C5...@hydro.com...
> I saw when I re-checked the SDK that it is listed in the "New WMI Classes"
> category, which is supposedly only implemented on XP...
>
> However on the Win32_PingStatus page they had this under Requirements:
> Windows NT/2000/XP: Requires Windows NT 4.0 SP4 or later
> Namespace: Included in \root\cimv2
> MOF: Declared in Ping_desc.mof
>
> Looks like another documentation "bug"...?
Hi
The Requirements part of the WMI documentation in MSDN can't be trusted at all.
At the top of the MSDN documentation of Win32_PingStatus
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/r_32os4_1xdf.asp
<qoute>
The Win32_PingStatus WMI class represents the values returned by the standard ping
command. More information on ping can be found in RFC 791. This class was added for
Windows XP.
</qoute>
--
torgeir
Sample code in wsf (both vbscript and JScript)
<job>
<script language="vbscript">
Option Explicit
On Error Resume Next
' All Visual Basic names are not case-sensitive (yuk)
'-------------------------
Function JsInputBox(sPrompt,sTitle,sDefault)
JSinputbox = InputBox(sPrompt,sTitle,sDefault)
End Function
'-------------------------
</script>
<script language="jscript">
//---------------------- JScript --- Main Routine -----------------------------
var sMachine;
sMachine = "192.168.200.005" // Default value for dialog box
sMachine = JsInputBox("Enter machine to ping", "Input Computer Address", sMachine);
if( ping(sMachine) ) {
WScript.echo("Machine " + sMachine + " responded to pinging.");
}
else {
WScript.echo("Machine " + sMachine + " did not respond to pinging.");
}
//-----------------------------------------------------------------------------
function ping(sMachine) {
var oPing
var sResp;
var oP;
var e;
var bResult;
try {
oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery(
"select * from Win32_PingStatus where address = '" + sMachine + "'");
for (e = new Enumerator(oPing); !e.atEnd(); e.moveNext()) {
oP = e.item();
sResp = oP.StatusCode;
break;
}
if (sResp == 0) {
//WScript.echo("Ping Status = 0, machine " + sMachine + " is responding.");
bResult = true;
}
else {
//WScript.echo("Ping Status not 0, machine " + sMachine + " is NOT responding.");
bResult = false;
}
}
catch(err) { ShowError(err); }
return(bResult);
}
//-----------------------------------------------------------------------------
function ShowError(error) {
var sMessage
var sFacilityCode;
var sErrorCode;
sFacilityCode = error.number >> 16 & 0x1FFF;
sErrorCode = error.number & 0xFFFF;
sMessage = "ERROR: 0x"+hex(error.number) + " " + error + "\n\n"+
"Name: " + error.name + "\n" +
"Description " + error.description + "\n" +
"Facility Code: " + sFacilityCode + "\n" +
"Error Code: " + sErrorCode + "\n" ;
WScript.echo(sMessage);
return(error);
}
//-----------------------------------------------------------------------------
function hex(nmb)
{
if (nmb > 0)
return nmb.toString(16);
else
return (nmb + 0x100000000).toString(16);
}
//-----------------------------------------------------------------------------
</script>
</job>
---
Gregory Phillips greg...@home.com Seattle, Washington, USA
> However on the Win32_PingStatus page they had this under Requirements:
> Windows NT/2000/XP: Requires Windows NT 4.0 SP4 or later
> Namespace: Included in \root\cimv2
> MOF: Declared in Ping_desc.mof
Is it possible that the .mof just needs to be compiled on NT?
If someone would post the Ping_desc.mof, I can try this out. I don't
have XP myself.
--Matt
However, I'm looking for something like that that works with Windows 2000.
:)
Not all my systems run XP.
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3CE368C5...@hydro.com...
I don't know, or use JS. What is the advantage of JS using case-sensitive?
Totally appreciate your help
Brian
"Gregory Phillips" <greg...@attbi.com> wrote in message
news:pls6euol1q4fppc4o...@4ax.com...
Brian
"msnews.microsoft.com" <btu...@hotmail.com> wrote in message
news:enExtWO$BHA.2252@tkmsftngp02...
Function IsConnectible(sHost,iPings,iTO)
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec("ping -n " & iPings _
& " -w " & iTO & " " & sHost)
Select Case InStr(oExCmd.StdOut.Readall,"100% loss")
Case 0 IsConnectible = True
Case Else IsConnectible = False
End Select
End Function
"msnews.microsoft.com" <btu...@hotmail.com> wrote in message
news:enExtWO$BHA.2252@tkmsftngp02...
Brian
"Alex K. Angelopoulos (MVP)" <alexangelop...@hotmail.com> wrote in
message news:Ov7QHmO$BHA.2192@tkmsftngp02...
> Ok, we have to fall back to the tried-and-true "IsConnectible" function.
>
> Function IsConnectible(sHost,iPings,iTO)
> ' sHost is a hostname or IP
> ' iPings is number of ping attempts
> ' iTO is timeout in milliseconds
> ' if values are set to "", then defaults below used
> If iPings = "" Then iPings = 2
> If iTO = "" Then iTO = 750
> Set oShell = CreateObject("WScript.Shell")
> Set oExCmd = oShell.Exec("ping -n " & iPings _
> & " -w " & iTO & " " & sHost)
> Select Case InStr(oExCmd.StdOut.Readall,"100% loss")
> Case 0 IsConnectible = True
> Case Else IsConnectible = False
> End Select
> End Function
Alex, you should consider doing this change:
- from -
Select Case InStr(oExCmd.StdOut.Readall,"100% loss")
- to -
sStdOut = oExCmd.StdOut.Readall
Select Case InStr(sStdOut,"100% loss") Or InStr(sStdOut,"Unknown host")
--
torgeir
> I think this is what I'm looking for. It's really fast and returns TRUE when
> the server is up. But when the server is down, it times out. No FALSE
> response. I dont know why. :\
Works perfectly for me.
Could you post the output from the ping run from a command prompt here (when the
server is down).
Note: You should obscure the real IP address/web address in the post
--
torgeir
XP's ping does one other thing with unknown hosts, an error message that says:
"Ping request could not find host xxx.xxx.xxx. Please check the name and try
again."
Looks like it should be:
Select Case InStr(sStdOut,"100% loss") OR InStr(sStdOut,"Unknown host") OR
InStr(sStdOut,"could not find host")
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3CE3FCE8...@hydro.com...
Just a suggestion.....
.............................
Select Case InStr(sStdOut,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
.............................
--
Gurgen Alaverdian
http://www.gurgensvbstuff.com
"Alex K. Angelopoulos (MVP)" <a...@mvps.org> wrote in message
news:uJk6lQR$BHA.2540@tkmsftngp05...
MUCH better.
"Gurgen" <gur...@bellatlantic.net> wrote in message
news:eV34TpR$BHA.2216@tkmsftngp02...
--
[MS] Scott McNairy
WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"msnews.microsoft.com" <btu...@hotmail.com> wrote in message
news:enExtWO$BHA.2252@tkmsftngp02...
Request Timed Out
Request Timed Out
Request Timed Out
Request Timed Out
Request Timed Out
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3CE3FE06...@hydro.com...
The usual message is:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Brian>ping 123.123.123.123
Pinging 123.123.123.123 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 123.123.123.123:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
However, sometimes the message is:
C:\Documents and Settings\Brian>ping nonameserver
Ping request could not find host nonameserver. Please check the name and try
aga
in.
Sometimes I've even seen it say something like:
Response from 192.168.1.1: Host not reachable.
"Alex K. Angelopoulos (MVP)" <a...@mvps.org> wrote in message
news:uJk6lQR$BHA.2540@tkmsftngp05...
Select Case InStr(sStdOut,"TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
"Brian" <su...@hotmail.com> wrote in message news:eUROZJd$BHA.2172@tkmsftngp04...
Brian
"Alex K. Angelopoulos (MVP)" <a...@mvps.org> wrote in message
news:eknuH#f$BHA.1108@tkmsftngp04...
Two things you can try:
(1) explicitly set iPings to 4 and iTO to about 3000 or so. See if it still
does it.
(2) If that doesn't fix the problem, try returning all of the results and
writing them to see the results:
Function PingResults(sHost,iPings,iTO)
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec("ping -n " & iPings _
& " -w " & iTO & " " & sHost)
PingResults = oExCmd.StdOut.Readall
End Function
"msnews.microsoft.com" <btu...@hotmail.com> wrote in message
news:O$1sV5PACHA.1916@tkmsftngp04...
The Server is Offline.
IP address must be specified.
here is the script as it has evolved from this thread:
----------------start
<% Response.Buffer = True %>
<%
shost=tibccswba01
iPings=1
iTO=3000
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec("ping -n " & iPings _
& " -w " & iTO & " " & sHost)
PingResults = oExCmd.StdOut.Readall
'Select Case InStr(sStdOut,"TTL=")
Select Case InStr(sStdOut,"100% loss") OR InStr(sStdOut,"Unknown host") OR
InStr(sStdOut,"could not find host") OR InStr(sStdOut,"Request timed out")
Case 0 IsConnectible = False
response.write "The Server is Offline." & "<br>"
response.write pingresults
Case Else IsConnectible = True
response.write "The Server is Online." & "<br>"
response.write pingresults
End Select
%>
----end
Running this from the command line out of asp however, the results are a
normal ping.
ping -n 2 -w 1000 shuttlecraft1
Your guess is as good as mine
"Alex K. Angelopoulos (MVP)" <a...@mvps.org> wrote in message
news:#DaemiUACHA.1680@tkmsftngp05...
The line above should be:
shost="tibccswba01"
>
> iPings=1
>
> iTO=3000
>
> ' sHost is a hostname or IP
>
> ' iPings is number of ping attempts
>
> ' iTO is timeout in milliseconds
>
> ' if values are set to "", then defaults below used
>
> If iPings = "" Then iPings = 2
>
> If iTO = "" Then iTO = 750
>
> Set oShell = CreateObject("WScript.Shell")
>
> Set oExCmd = oShell.Exec("ping -n " & iPings _
>
> & " -w " & iTO & " " & sHost)
>
>
> PingResults = oExCmd.StdOut.Readall
>
>
> 'Select Case InStr(sStdOut,"TTL=")
>
> Select Case InStr(sStdOut,"100% loss") OR InStr(sStdOut,"Unknown host") OR
> InStr(sStdOut,"could not find host") OR InStr(sStdOut,"Request timed out")
>
> Case 0 IsConnectible = False
>
> response.write "The Server is Offline." & "<br>"
>
> response.write pingresults
>
> Case Else IsConnectible = True
>
> response.write "The Server is Online." & "<br>"
>
> response.write pingresults
>
> End Select
>
> %>
>
--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--
> > shost=tibccswba01
>
> The line above should be:
>
> shost="tibccswba01"
Not only that, his Case test is based on the variable sStdOut that he has not
defined.
--
torgeir
Ok Brian, here is a updated version of your script that should work:
<% Response.Buffer = True %>
<%
shost="tibccswba01"
iPings=1
iTO=3000
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec("ping -n " & iPings _
& " -w " & iTO & " " & sHost)
PingResults = oExCmd.StdOut.Readall
Select Case InStr(PingResults,"TTL=")
Case 0 IsConnectible = False
response.write "The Server is Offline." & "<br>"
'response.write pingresults
Case Else IsConnectible = True
response.write "The Server is Online." & "<br>"
'response.write pingresults
End Select
%>
--
torgeir
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3CEBEA97...@hydro.com...