pinging with WScript.Shell

T

Todd

Hello I'm using the following script to try and ping:

<% Response.Buffer = true %>
<%
url = "www.espn.com"

Set objWShell = CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("ping " & url)
strPResult = objCmd.StdOut.Readall()
set objCmd = nothing: Set objWShell = nothing

strStatus = "offline"
if InStr(strPResult,"TTL=")>0 then strStatus = "online"

response.write url & " is " & strStatus
response.write ".<br>" & replace(strPResult,vbCrLf,"<br>")
%>

I am getting the following error on the objWShell.Exec("ping " & url):

WshShell.Exec error '80070005'

Access is denied.

/test.asp, line 6


I can understand there being permssions errors if I was moving files around
in different directories but this is a straight ping. There shouldnt be any
permissions error by my thinking. Any help would be appreciated.

Thank You
 
E

Evertjan.

=?Utf-8?B?VG9kZA==?= wrote on 14 mrt 2008 in
microsoft.public.inetserver.asp.general:
Hello I'm using the following script to try and ping:

<% Response.Buffer = true %>
<%
url = "www.espn.com"

Set objWShell = CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("ping " & url)
strPResult = objCmd.StdOut.Readall()
set objCmd = nothing: Set objWShell = nothing

strStatus = "offline"
if InStr(strPResult,"TTL=")>0 then strStatus = "online"

response.write url & " is " & strStatus
response.write ".<br>" & replace(strPResult,vbCrLf,"<br>")
%>

I am getting the following error on the objWShell.Exec("ping " & url):

WshShell.Exec error '80070005'

Access is denied.

/test.asp, line 6


I can understand there being permssions errors if I was moving files
around in different directories but this is a straight ping. There
shouldnt be any permissions error by my thinking. Any help would be
appreciated.

read this perhaps:

<http://www.microsoft.com.nsatc.net/technet/scriptcenter/resources/qanda/
sept04/hey0914.mspx>
 
T

Todd

Evertjan. said:
=?Utf-8?B?VG9kZA==?= wrote on 14 mrt 2008 in
microsoft.public.inetserver.asp.general:


read this perhaps:

<http://www.microsoft.com.nsatc.net/technet/scriptcenter/resources/qanda/
sept04/hey0914.mspx>

Tried both Win 2000 options on that site and getting the same errors at the
same locations (.Exec on the first one and .Run on the second. For your
convenience here si the two scripts I tried running (replacing the IP with
something local to me).

Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec _
("%comspec% /c ping -n 3 -w 1000 192.168.1.1")
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received."
Else
Wscript.Echo "No reply received."
End If
Loop

--------------------------------------------

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
objName = objFSO.GetTempName
objTempFile = objName
objShell.Run "cmd /c ping -n 3 -w 1000 192.168.1.1 >" & _
objTempFile, 0, True
Set objTextFile = objFSO.OpenTextFile(objTempFile, 1)
Do While objTextFile.AtEndOfStream <> True
strText = objTextFile.ReadLine
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received."
Exit Do
End If
Loop
objTextFile.Close
objFSO.DeleteFile(objTempFile)

Hope this helps narrow down the problem.

Thank You
 
P

p byers

Hi Bob

I took the example on the page you gave us.

I pasted it into a file called "ping.asp"

I wanted it not particularly for 'Pinging' but to give me a Template
for using WSH in Classic .ASP pages

I am lucky enough to have access to six servers of a whole range of Operating Systems
ranging from ancient to Windows 2003 Server (IIS6)

On all six of them, I got the following Error


======================================
WshShell.Exec error '80070005'

Access is denied.

/test/ping.asp, line 6


======================================

Advice please

Pete (Northolt UK)
 
B

Bob Barrows [MVP]

I was able to get it to work by disabling Anonymous on my test site so that
the wsh code was run under my user context.

If disableing Anonymous is not an option for you, then you need to configure
IIS to use an impersonation account with admin rights on your site. If that
is not an option (and it is not an action I would suggest taking on an
internet site given the security risks involved) then you are out of luck as
far as I know.
 
P

p byers

Thanks Bob - will try what you suggest


Bob Barrows said:
I was able to get it to work by disabling Anonymous on my test site so that
the wsh code was run under my user context.

If disableing Anonymous is not an option for you, then you need to configure
IIS to use an impersonation account with admin rights on your site. If that
is not an option (and it is not an action I would suggest taking on an
internet site given the security risks involved) then you are out of luck as
far as I know.



--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top