Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

wscript.shell not working in asp..help

Last post 07-11-2008 11:00 AM by Veritant. 19 replies.
Page 1 of 2 (20 items) 1 2 Next >
Sort Posts: Previous Next
  • 08-26-2005 1:14 PM

    wscript.shell not working in asp..help

    Hi all,

    I have the following code in my ASP page:

    Dim wshell
    set wshell = server.createobject("wscript.shell")
    wshell.Run "notepad" & " c:\textfile.txt", 1, true
    Response.Write("Ends here")

    The problem is that, it neither shows any error nor it gets executed completely.

    If I write something like:

    Dim wshell
    set wshell = server.createobject("wscript.shell")
    Response.Write("Ends here")

    it works fine and displays the "Ends here" message.

    The   wshell.Run "notepad" & " c:\textfile.txt", 1, true    statement seems to have some problem, dont know what.

    Please help.
    Thanks in advance.
    • Post Points: 15
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 08-26-2005 11:03 PM In reply to

    • Veritant
    • Top 50 Contributor
    • Joined on 11-02-2001
    • United Kingdom
    • Guru
    • Points 1,975

    Not sure then...

    I think it might be a permission problem. Try this code to report any error:
    Code:

    <%
    Dim wshell
    set wshell = server.createobject("wscript.shell")
    Response.Write("Starts here<br/>")

    on error resume next

    %>
    <pre>
    <%=now()%>

    </pre>
    <%

    wshell.Run "notepad.exe  c:\temp\textfile.txt", 1, false

    Response.write "Passed through<br/>"

    if err.number <> 0 then
       response.write "Error detected: " & err.number & ": " & err.Description & "<br/>"
       on error goto 0
       response.end
    end if
    on error goto 0
    Response.write "Run sucessfully<br/>"
    %>

    <pre>
    <%=now()%>

    </pre>
    Veritant (John)
    • Post Points: 15
  • 08-27-2005 5:00 PM In reply to

    • webjose
    • Top 10 Contributor
    • Joined on 01-02-2002
    • Guru
    • Points 11,015

    Wink [;)] Why do you need this?

    It is awful strange to me that you want the server to open Notepad.  Is there anyone logged into the server actually requiring that Notepad opens based on a client visiting certaing webpage?  It doesn't make much sense to me.

    Or maybe you are trying to show notepad in the client's computer?  If you are trying to do that, then you have the code in the wrong side:  You need a VBScript that runs in the CLIENT side.
    Code:
    <script language="VBScript">
    <!--
    Dim oScript = CreateObject("WScript.Shell")
    oScript.Run "notepad.exe " & strFilename, 1, True
    -->
    </script>
    • Post Points: 5
  • 08-29-2005 5:24 AM In reply to

    Not sure then...

    Hello webjose


    Thanks for your reply.

    Actually i am not opening a notepad on the server. I have an exe that i want to run on the server each time the page is hit. But due to some reason the page just keeps on executing. It neither gives an error nor the exe executes.

    The above code i provided is just an example i tried to execute, but that too didnt worked.

    I need more inputs from you guys on this. Please help.

    Thanks once again.
    • Post Points: 5
  • 08-30-2005 10:25 PM In reply to

    • Veritant
    • Top 50 Contributor
    • Joined on 11-02-2001
    • United Kingdom
    • Guru
    • Points 1,975

    Not sure then...

    Did you try the code I posted? This code reports the error back to the browser so you can see what error occurred.

    Another option, which I have used successfully in the past, is to have the web page create or rename a file on the server. Then have a script running on the server that checks for the presence of the file every, say, 30 seconds, and if the file is present runs the application and deletes or renames back the file. The reason I did this is that it is not advisable to allow the execute permission on IIS, and you can choose which user to run the application under when you set up the script.
    Veritant (John)
    • Post Points: 5
  • 08-31-2005 3:20 AM In reply to

    • webjose
    • Top 10 Contributor
    • Joined on 01-02-2002
    • Guru
    • Points 11,015

    Cool [H] Not sure then...

    Normally, you cannot make the ASP page run an executable that shows a user interface.  Does your application show a user interface, like a form or a message box?  If so, I don't think you'll be able to use it.

    Another thing:  I have searched microsoft.com for information on shelling out processes and I have only found examples of COM out-of-process servers... I'm starting to wonder if COM is the only way to go with exe's....
    • Post Points: 5
  • 08-31-2005 6:12 AM In reply to

    Smiley Face [:)] Not sure then...

    Hi Veritant,

    Thanks for the code you gave and it worked fine without any error.

    Then I tried to run the exe which I actually want to run from my ASP page. I made the exe in Visual Basic, the code for which is as follows:

    Sub Main()

    Set oIELinkGeneral = CreateObject("InternetExplorer.Application")
    Call oIELinkGeneral.Navigate("http://www.linkgeneral.com/logon.asp")

    oIELinkGeneral.Visible = False

    While oIELinkGeneral.ReadyState <> 4 Or oIELinkGeneral.Busy
    Wend

    oIELinkGeneral.document.Forms(1).Logon.Value = "seema"
    oIELinkGeneral.document.Forms(1).password.Value = "12345"
    oIELinkGeneral.document.Forms(1).LogonBtn.Click

    While oIELinkGeneral.ReadyState <> 4 Or oIELinkGeneral.Busy

    Wend

    Call oIELinkGeneral.Navigate("http://www.linkgeneral.com/author.asp?addarticle=yes")

    While oIELinkGeneral.ReadyState <> 4 Or oIELinkGeneral.Busy

    Wend

    oIELinkGeneral.document.Forms(1).subject.Value = "demo"
    oIELinkGeneral.document.Forms(1).shortdescription.Value = "demoDescription"
    oIELinkGeneral.document.Forms(1).catid.Value = "791"
    oIELinkGeneral.document.Forms(1).articletext.Value = "demo article"

    oIELinkGeneral.document.Forms(1).submitarticle.Click

    While oIELinkGeneral.ReadyState <> 4 Or oIELinkGeneral.Busy
    Wend

    Call oIELinkGeneral.Navigate("http://www.linkgeneral.com/logon.asp?logout=yes")

    While oIELinkGeneral.ReadyState <> 4 Or oIELinkGeneral.Busy
    Wend

    End Sub

    I have written this code in a Module and in that VB Project there is only one module, no forms nothing. I made an exe of the project and saved it on the C: of the server.

    Then in the code you provided i changed the line:

    wshell.Run "notepad.exe  c:\temp\textfile.txt", 1, false

    to:

    wshell.Run "c:\Project1.exe", 1, false

    When I call the asp page it runs fine without any error. But, as you can see in the above code, I am trying to submit an article in that site, and when I go to that site I dont see any article submitted.

    One more thing that I noticed is, when I checked the Task Manager on the server, I can see the exe still running under the Processess tab.

    Can you please tell me what I should do to make it work?

    Thanks once again.

    PS: I got the following messages when I called the exe from ASP page

    Starts here


    8/31/2005 10:28:08 AM


    Passed through
    Run sucessfully


    8/31/2005 10:28:08 AM

    • Post Points: 10
  • 02-22-2007 9:48 AM In reply to

    • Thilak
    • Not Ranked
    • Joined on 02-22-2007
    • New Member
    • Points 10

    still having the same problem

    I too getting the same problem..

    When I try to run the following asp codes, it runs fine without any error. But nothing as coming in the screen.. I checked the Task Manager on the server, I can see the exe still running under the Processess tab.
     

    Please tell me the solution for this

    set SO = Server.CreateObject("WScript.SHELL")

    so.Run "C:\CinergicSystem\Applications\Compiled\Scanner.exe", 1, FALSE

    so.Run "%SystemRoot%\System32\calc.exe", 1, FALSE

    Response.write "Passed through"

    if err.number <> 0 then

       response.write "Error detected: " & err.number & ": " & err.Description & ""

    on error goto 0

    response.end

    end if

    on error goto 0

    Response.write "Run sucessfully"

    set so = nothing

     

    Cheers

    thilak

    • Post Points: 5
  • 02-22-2007 9:53 AM In reply to

    • Thilak
    • Not Ranked
    • Joined on 02-22-2007
    • New Member
    • Points 10

    Re: still having the same problem

    another query:

    how to call a VB DLL program from ASP. That VB dll program should call an .EXE program/file.

     

    • Post Points: 5
  • 03-25-2007 3:23 AM In reply to

    message error

    Error detected: 70: Permiso denegado

     

    What I Do??

    • Post Points: 5
  • 07-09-2008 4:01 PM In reply to

    • jonpfl
    • Not Ranked
    • Joined on 07-09-2008
    • United States
    • New Member
    • Points 60

    Re: Not sure then...

    Veritant:
    I think it might be a permission problem. Try this code to report any error:
    Code:

    <%
    Dim wshell
    set wshell = server.createobject("wscript.shell")
    Response.Write("Starts here<br/>")

    on error resume next

    %>
    <pre>
    <%=now()%>

    </pre>
    <%

    wshell.Run "notepad.exe  c:\temp\textfile.txt", 1, false

    Response.write "Passed through<br/>"

    if err.number <> 0 then
       response.write "Error detected: " & err.number & ": " & err.Description & "<br/>"
       on error goto 0
       response.end
    end if
    on error goto 0
    Response.write "Run sucessfully<br/>"
    %>

    <pre>
    <%=now()%>

    </pre>

    I tried adding that to my code and it never returned.  I assume I must have a permission problem but I do not know how to solve it?

     Any ideas?

     Thx

    jonpfl

    PS How do I turn off double spacing???

    • Post Points: 10
  • 07-09-2008 4:17 PM In reply to

    • Veritant
    • Top 50 Contributor
    • Joined on 11-02-2001
    • United Kingdom
    • Guru
    • Points 1,975

    Re: Not sure then...

    Hi Jon
    I am not sure of the problem here. You may be right that there is a permission problem, but I would expect that to be reported. You say you tried adding this to your code, but what is the rest of the code? Could there be some problem elsewhere?
    Did you try running the code I posted in a separate page, just to check that the basic mechanism works?
    You could add response.flush to push the output to the page to see how far it gets, that might help to narrow down the area in which the problem is.
    Good Luck!

    If you use <shift><return> at the end of each line that will give you single spacing.

     

    Veritant (John)
    • Post Points: 10
  • 07-09-2008 6:22 PM In reply to

    • jonpfl
    • Not Ranked
    • Joined on 07-09-2008
    • United States
    • New Member
    • Points 60

    Re: Not sure then...

    Here are my two pages and it is still hanging :

    jon.asp

    <%@ Language=VBScript %> <% Option Explicit %>

    <%

    Dim WSHShell, WshEnv

    Set WSHShell = CreateObject("WScript.Shell")

    Set WSHEnv = WSHShell.Environment("Process") WSHEnv("SEE_MASK_NOZONECHECKS") = 1

    Response.Write("Starts here<br/>")

    on error resume next

    %>

    <pre>

    <%=now()%>

    </pre>

    <%

    WSHShell.Run server.MapPath("\credit_reporting\maintenance\business_subjects\jon_test.vbs"), 1, true

    WSHEnv.Remove("SEE_MASK_NOZONECHECKS")

    Response.write "Passed through<br/>"

    if err.number <> 0 then

    response.write "Error detected: " & err.number & ": " & err.Description & "<br/>"

    on error goto 0

    response.end

    end if

    on error goto 0 Response.write "Run sucessfully<br/>"

    %>

    <pre>

    <%=now()%>

    </pre>

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <title>jon</title>

    </head> <body onload="">

    <table width="100%">

    <tr><td>test</td></tr>

    </table>

    </body> </html>


    Here is the vbs file :

    dim Mail

    set Mail = CreateObject("CDO.Message")

    'fill email fields

    Mail.From="xxx@xxx.com"

    Mail.To="xxx@xxx.com"

    Mail.Subject="test"

    Mail.HTMLBody = "test"

    Mail.Send 'email this message

    set Mail = Nothing


    • Post Points: 5
  • 07-09-2008 7:14 PM In reply to

    • jonpfl
    • Not Ranked
    • Joined on 07-09-2008
    • United States
    • New Member
    • Points 60

    Re: Not sure then...

    Veritant:

    Hi Jon
    I am not sure of the problem here. You may be right that there is a permission problem, but I would expect that to be reported. You say you tried adding this to your code, but what is the rest of the code? Could there be some problem elsewhere?
    Did you try running the code I posted in a separate page, just to check that the basic mechanism works?
    You could add response.flush to push the output to the page to see how far it gets, that might help to narrow down the area in which the problem is.
    Good Luck!

    If you use <shift><return> at the end of each line that will give you single spacing.

     



    If you give me some code that you know works for you, I can try it on my end and see what happens.  Maybe that is a better idea.

    Thx
    jonpfl

    • Post Points: 5
  • 07-09-2008 7:53 PM In reply to

    • jonpfl
    • Not Ranked
    • Joined on 07-09-2008
    • United States
    • New Member
    • Points 60

    Re: Not sure then...

    I tried doing this


    sTemp = "cscript " & server.MapPath("\credit_reporting\maintenance\business_subjects\jon_test.vbs")

    'WSHShell.Run server.MapPath("\credit_reporting\maintenance\business_subjects\jon_test.vbs"), 1, true

    WSHShell.Run sTemp




    And get this :

    Starts here

     
    7/9/2008 2:49:26 PM 
    
    

    Passed through
    Error detected: 70: Permission denied

    Thoughts?
    jonpfl

    • Post Points: 10
Page 1 of 2 (20 items) 1 2 Next >