WScript and ASP question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonpfl
    New Member
    • Feb 2007
    • 31

    WScript and ASP question

    All,

    Can I use WScript inside an ASP page to kick off another process and post back to the client while this other process is still running?

    The reason I want to do this is because we are creating PDFs and they are taking as long as 2 mins (alot of processing to create PDFs) and we would like to have it as an offline process and email it to them when it is done and not have them waiting at a webpage for completion.

    Thx
    jonpfl
  • jonpfl
    New Member
    • Feb 2007
    • 31

    #2
    This is what I am doing on my .asp page

    Code:
    Dim WSHShell, WshEnv
    Set WSHShell = CreateObject("WScript.Shell")
    Set WSHEnv = WSHShell.Environment("Process")
    WSHEnv("SEE_MASK_NOZONECHECKS") = 1
    WSHShell.Run(server.MapPath("/credit_reporting/maintenance/jon_test.vbs"))
    'WSHShell.Run("notepad")
    WSHEnv.Remove("SEE_MASK_NOZONECHECKS")
    And in my /credit_reportin g/maintenance/jon_test.vbs file, I don't have anything right now. I am just testing to see if this is going to work and I am getting an error.

    Is there a special format I need in my jon_test.vbs file?

    Thx
    jonpfl

    Comment

    • DrBunchman
      Recognized Expert Contributor
      • Jan 2008
      • 979

      #3
      I think I'm right in saying that once you start to run a vbs script from a shell your ASP code will continue to process but it should be easy enough to test.

      What's the error you're getting?

      Dr B

      Comment

      • jonpfl
        New Member
        • Feb 2007
        • 31

        #4
        My dumb mistake of not having the right path!!!

        But that leads to another problem. I have the following in my ASP page

        Code:
        Dim WSHShell, WshEnv
        Set WSHShell = CreateObject("WScript.Shell")
        Set WSHEnv = WSHShell.Environment("Process")
        WSHEnv("SEE_MASK_NOZONECHECKS") = 1
        response.Write "jon1"
        response.Write WSHShell.Run(server.MapPath("\credit_reporting\maintenance\business_subjects\jon_test.vbs"))
        WSHEnv.Remove("SEE_MASK_NOZONECHECKS")
        response.Write "jon2"
        And the following for jon_test.vbs
        Code:
        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
        And I never receive and email from the ASP page. If I go onto the server and run the script, I get an email (mind you, I deleted my actual email address).

        Any thoughts?

        Thx
        jonpfl

        Comment

        • jonpfl
          New Member
          • Feb 2007
          • 31

          #5
          Actually, here is some more info

          If I add the following info, the page never returns. I assume this means this is a permission problem since this code is waiting for a return, right?

          Code:
          WSHShell.Run (server.MapPath("\credit_reporting\maintenance\business_subjects\jon_test.vbs"), 1, true)
          Any thoughts?

          Thx
          jonpfl

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            Correct, the third parameter is a boolean which determines whether your program will wait for the completion of the script.

            If it never continues running then there is a problem with your script not finishing. Do you get a window on the server when the script is called?

            Dr B

            Comment

            • jonpfl
              New Member
              • Feb 2007
              • 31

              #7
              Originally posted by DrBunchman
              Correct, the third parameter is a boolean which determines whether your program will wait for the completion of the script.

              If it never continues running then there is a problem with your script not finishing. Do you get a window on the server when the script is called?

              Dr B
              Should I be getting a window if I have the 2nd param as 1?

              What user does an ASP page run under?

              Thx
              jonpfl

              Comment

              • DrBunchman
                Recognized Expert Contributor
                • Jan 2008
                • 979

                #8
                The second paramater IS specifying that it opens a window - whether it will or not I don't know as the script is very short and you aren't writing to the screen.

                The name that an ASP page runs under depends on the security settings you specify in the IIS console. If you are using anonymous auth then it will use the IUSR_<machine name> account; if you are using windows auth then it will use the logged in user's account.

                Why do you think you're getting permission problems?

                Dr B

                Comment

                • jonpfl
                  New Member
                  • Feb 2007
                  • 31

                  #9
                  Originally posted by DrBunchman
                  The second paramater IS specifying that it opens a window - whether it will or not I don't know as the script is very short and you aren't writing to the screen.

                  The name that an ASP page runs under depends on the security settings you specify in the IIS console. If you are using anonymous auth then it will use the IUSR_<machine name> account; if you are using windows auth then it will use the logged in user's account.

                  Why do you think you're getting permission problems?

                  Dr B
                  Because I am setting the 3rd variable to true which means it has to wait for the script to complete before continuing in, right?

                  Well, when I run this script, it just hangs and the page never returns. I was assuming it was a permission problem

                  Thx
                  jonpfl

                  Comment

                  • DrBunchman
                    Recognized Expert Contributor
                    • Jan 2008
                    • 979

                    #10
                    Yes it should wait.

                    What happens if you reduce the vbs script to something really, really simple like one line? Does it still hang then?

                    Dr B

                    Comment

                    • jonpfl
                      New Member
                      • Feb 2007
                      • 31

                      #11
                      Originally posted by DrBunchman
                      Yes it should wait.

                      What happens if you reduce the vbs script to something really, really simple like one line? Does it still hang then?

                      Dr B
                      Yes, I tried putting one line in the vbs page and it still hung (Dim Mail)

                      These are the two pages I have now :

                      jon.asp
                      Code:
                      <%@ 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 jon_test.vbs
                      Code:
                      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
                      Any ideas from this? Is there something on IIS that could be stopping this from returning?

                      Thx
                      jonpfl

                      Comment

                      • jonpfl
                        New Member
                        • Feb 2007
                        • 31

                        #12
                        If you can give me some code you have working for WScript, I can try copying it into my pages to see if it works for me.

                        Thx
                        jonpfl

                        Comment

                        • jonpfl
                          New Member
                          • Feb 2007
                          • 31

                          #13
                          Ok, I changed my code to this

                          Code:
                          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 I get the following :

                          Starts here


                          7/9/2008 2:49:26 PM


                          Passed through
                          Error detected: 70: Permission denied


                          Thoughts?
                          jonpfl

                          Comment

                          • jonpfl
                            New Member
                            • Feb 2007
                            • 31

                            #14
                            Ok, I got it working. My admin guy gave read/execute permission to the cscript.exe file in the windows/system32 directory.

                            Now, when I try to execute the script from the server, it creates the file as expected. When I try to create the file via the ASP page, it completes but the file does not get created.

                            Thoughts?
                            jonpfl

                            Comment

                            • DrBunchman
                              Recognized Expert Contributor
                              • Jan 2008
                              • 979

                              #15
                              I'd take out the error trapping from your ASP page - at this stage you want it to break so you can see what's going on.

                              You need to see whether the problem is the script itself (which it probably isn't as this works when run separately) or the shell.

                              If you run it without error trapping what happens? Does it still process the page okay or does it error?

                              Dr B

                              Comment

                              Working...