Calling WSH scripts from ASP

Discussion in 'ASP General' started by Bob, Jun 19, 2006.

  1. Bob

    Bob Guest

    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, Jun 19, 2006
    #1
    1. Advertising

  2. Bob

    Slim Guest

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



    "Bob" <> wrote in message
    news:...
    >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, Jun 20, 2006
    #2
    1. Advertising

  3. Bob

    Bob Guest

    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
    Bob, Jun 20, 2006
    #3
  4. Bob

    Bob Guest

    Re: Calling WSH scripts from ASP - SOLUTION

    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
    Bob, Jun 21, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kyiu

    lost in ASP & WSH!please help!

    kyiu, Jul 11, 2003, in forum: ASP General
    Replies:
    1
    Views:
    146
    Dhananjay Modak
    Jul 11, 2003
  2. Karen

    client-side WSH in ASP

    Karen, Jul 21, 2003, in forum: ASP General
    Replies:
    0
    Views:
    104
    Karen
    Jul 21, 2003
  3. Lorenzo Bolognini

    [XPOST] Controlling the commandline via ASP/WSH

    Lorenzo Bolognini, Aug 15, 2003, in forum: ASP General
    Replies:
    0
    Views:
    117
    Lorenzo Bolognini
    Aug 15, 2003
  4. Yitzhak
    Replies:
    2
    Views:
    326
    Jonathan B.
    Jan 21, 2004
  5. ben h

    Can I call a WSH from ASP?

    ben h, Jul 8, 2004, in forum: ASP General
    Replies:
    1
    Views:
    101
    Michael Harris \(MVP\)
    Jul 8, 2004
Loading...

Share This Page