Calling WSH scripts from ASP
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > IIS server support > IIS ASP > Calling WSH scripts from ASP




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Calling WSH scripts from ASP  
Bob


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-19-06 06: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
= = = = = = = = = = = = = = = = = = = = = = = =






[ Post a follow-up to this message ]



    Re: Calling WSH scripts from ASP  
Slim


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-20-06 12:25 PM

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







[ Post a follow-up to this message ]



    Re: Calling WSH scripts from ASP  
Bob


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-20-06 06: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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:55 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register