Calling WSH scripts from ASP

B

Bob

I have created some WSH scripts on my Webserver that are executed by
the Windows Task Scheduler. I want to be able to execute some of these
scripts using a web interface and don't want to duplicate these scripts
in ASP. I know this can be done using the WScript.Shell run method but
I am having no success. Below is a test application I have thrown
together to demonstrate my problem.

If I run c:\intetpub\wwwroot\wshasp\storetime.vbs from the server's
command line it appends the text file
c:\intetpub\wwwroot\wshasp\storetime.vbs with the current time. I can
do this forever and it keeps adding the time to the file, no problem
whatsoever. If I run the ASP using a browser I get nothing, no errors,
just a browser page with "objWSH.run Result: 0", no time is appended to
storedtime.txt, no errors are recorded in any logs.

I have adjusted security settings for iusr_MACHINENAME to allow
read/write/execute.

Finally, I have successfully used the wscript.shell object in an ASP
function to make a direct call to ping, dir, etc. and pipe the results
to a text file.

I have incorporated many things in the following code that I found
searching this group and many links found on Google. Nothing seems to
work, any ideas?


EXAMPLE CODE FOLLOWS

c:\intetpub\wwwroot\wshasp\default.asp:
= = = = = = = = = = = = = = = = = = = = = = = =
<% @ Language = "VBScript" %>
<%
option explicit

function testScript()
dim objWSH
dim intReturn

intReturn = 7 'initialized the value to insure it changed
set objWSH = server.createObject("wscript.shell")
intReturn = objWSH.run("c:\intetpub\wwwroot\wshasp\storetime.vbs")
set objWSH = nothing
response.write("objWSH.run Result: " & intReturn & "<br />")
end function 'daily_scripts
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Test WSH</title>

</head>

<body>

<%
testScript()
%>

</body>

</html>
= = = = = = = = = = = = = = = = = = = = = = = =


c:\intetpub\wwwroot\wshasp\storetime.vbs:
= = = = = = = = = = = = = = = = = = = = = = = =
option explicit
dim objFSO
dim objTextFile

set objFSO = createObject("scripting.fileSystemObject")
set objTextFile =
objFSo_OpenTextFile("c:\intetpub\wwwroot\wshasp\storedtime.txt", 8,
true)
objTextFile.writeLine(now())
objTextFile.close
set objTextFile = nothing
set objFSO = nothing
= = = = = = = = = = = = = = = = = = = = = = = =
 
S

Slim

Dim oShell
Set oShell = Server.CreateObject("WSCript.shell")
dScript = "wscript \\hank\scripts\test.vbs"
try = oShell.Run(dScript)
Response.Write try
 
B

Bob

Slim, thanks but . . .


function testScript()
dim objWSH
dim intReturn
' edit
dim strRun
' /edit
intReturn = 7 'initialized the value to insure it changed
set objWSH = server.createObject("wscript.shell")
' edit
strRun = "wscript c:\intetpub\wwwroot\wshasp\storetime.vbs"
intReturn = objWSH.run(strRun)
' /edit
set objWSH = nothing
response.write("objWSH.run Result: " & intReturn & "<br />")
end function 'testScript


Same result (no vbs execution). Again, thanks for the reply.
 
B

Bob

For those interested I found a solution. I had not specified the
command interpreter. See the edited line. You can use either "cmd" or
"%comspec%" to call the primary or secondary command interpreters
respectively.

function testScript()
dim objWSH
dim intReturn

intReturn = 7 'initialized the value to insure it changed
set objWSH = server.createObject("wscript.shell")
'edit
intReturn = objWSH.run("cmd /c
c:\intetpub\wwwroot\wshasp\storetime.vbs, 0, true")
'/edit
set objWSH = nothing
response.write("objWSH.run Result: " & intReturn & "<br />")
end function 'testScript
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top