wscript.shell not working in asp..help

asp India
  • 15 years ago

    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.

  • 15 years ago

    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>

  • 15 years ago
    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>
  • 15 years ago

    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.

  • 15 years ago

    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.

  • 15 years ago

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

  • 15 years ago

    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


  • 14 years ago

    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

  • 14 years ago

    another query:

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

     

  • 13 years ago

    Error detected: 70: Permiso denegado

     

    What I Do??

  • 12 years ago

    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.

     

  • 12 years ago

    Looks to me like you need to allow script and/or executable permission on the "business_subjects" subfolder. You should be able to do this in IIS (right-click on the folder in IIS and choose properties). If you allow executable permission, then don't allow write permission on the same folder, as this opens a potential opportunity for someone to write an executable to the folder and run it.

  • 12 years ago

    I think the most likely problem is, again, permissions on folders - this time write permission for the pdf file. When you run the script yourself it will be run with your own user id's permissions, and you have the necessary permission to write to the folder. When it is run from the asp page, the user will probably be whatever has been set up in IIS as the user account for anonymous access (I think this is by default something like IUSR_<server name>). It is likely that this user does not have write permissions on the folder to which the application is trying to write the pdf.

    Another possibility: I think when you double-click on a vbs script, the default is to use wscript, not cscript. There may be some difference between these when running your script. Is there any input required to the script when it is run that it may be failing on?

  • 12 years ago

    There's still a permission problem somewhere. Some suggestions...

    1. Try putting the email code directly in the asp page, and see if it runs OK. As a matter of interest, why are you running it in a separate shell anyway?

    2. Have you allowed script & executable permission on the \credit_reporting\maintenance\business_subjects (virtual) folder within IIS itself?

    3. I thought you would have to set the SMTP server address, email account name and email account password as parameters on the Message object before you can send?

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The difference between theory and practice is smaller in theory than in practice.”