IIS ASP - Calling WSH scripts from ASP

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > June 2006 > Calling WSH scripts from ASP





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Calling WSH scripts from ASP
Bob

2006-06-19, 1:22 pm

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
= = = = = = = = = = = = = = = = = = = = = = = =

Slim

2006-06-20, 7:25 am

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



"Bob" <newsome.bob@gmail.com> wrote in message
news:1150740156.189420.38730@p79g2000cwp.googlegroups.com...
>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
> = = = = = = = = = = = = = = = = = = = = = = = =
>



Bob

2006-06-20, 1:23 pm

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.


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


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com