Running a batch from ASP

Posted on 2006-12-01
Last Modified: 2010-04-06
Below is my code for running a batch/exe from within ASP

dirPath = server.mappath(".")
dirPath = dirPath & "\update.exe"
response.write dirPath

Set WShShell = Server.CreateObject("WScript.Shell")

RetCode = WShShell.Run(dirPath,10,true)

Set WShShell = Nothing

When I run this it appears to do nothing - I ran it multiple times.   Then it dawned on me to check Task Manager for Processes running.   I'll be darned if there weren't multiple instances of that executable running owned by the IWAM user, but within the asp it never appeared to do anything or actually open the executable.    I also switched update.exe to a batch that simple opened notepad.exe and got the same result.   Any idea what I'm missing to make this execute properly?  

Question by:acco_is
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 11

Expert Comment

ID: 18057052
What is your objective with this script?

ASP is for processing scripts, usually VBScript, which generate HTML for IIS to serve to a web browser. The response.write command above will return the directory path to the output stream to be displayed by the requesting web visitor. The script will launch update.exe to run in the current user space which, if launched by IIS, is IWAM_servername. If you could log in as IWAM_servername, you'd find the updater running there.

If you log into the server and double-click the script locally, it should launch updater.exe in the logged in user space. I'm not sure what VBScript would do with the response.write command, though. I think that's strictly an ASP command. You'd need something like a prompt command to show the directory path on the screen.

Author Comment

ID: 18069002
Well, I'm not sure that really answers the question.    I understand what the response.write does.   I'm just wanting to know what change I need to make in order for it to RUN the executable or batch file instead of under the IWAM account?   I know I got this to work fine a few years ago, but can't seem to reproduce it.  

Any other ideas?   Does it need to ran as a different user?  

LVL 11

Expert Comment

ID: 18069179
If you launch an application remotely by opening an ASP file on the server in your browser on your desktop, the application will be launched in the IWAM_servername user space. If that application does not require interaction, it will run and terminate. But if it does require interation, it will stay resident awaiting a response from the IWAM_servername user which will never come as there is no way to log in as IWAM_servername. So it will remain resident in the IWAM_servername user space until the server is restarted or the app is forced to quit using task manager.

Again, what is your objective? Are you expecting the app to load into your remote browser? I'm not familiary with any way to do that with ASP or any other web-based scripting. That type of function requires some sort of terminal interface into the server.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 18069437
Well, we have an application that is entirely web based.   There is another software application that we will be passing data to.   I am creating a data file in XML and then need to call an executable or batch file that will process/write this data in to the other company's software.   Basically want a "click one button" to simplify things for the users.   If you follow me.

I've done it in an ASP page, calling a batch file to kick off an ftp call.  I just can't get the same to work here.  I have a few more ideas.    Any other thoughts?

LVL 11

Accepted Solution

walkerke earned 500 total points
ID: 18069714
You may want to test your .bat file locally to see if it's generating a user prompt or an error. The "true" attribute in the WShShell.Run means the script will wait for the .bat file to complete before continuing. Errors will only be returned to the script once the .bat file terminates. If it's waiting for a user response, the script will remain in limbo until the response is received and the .bat file is finished. This particular command is designed more for locally executed VBScript than for remotely executed ASP.

Author Comment

ID: 18069772
Ok, so that makes more sense why the return code for errors is 0.   Its isn't erroring at all, its actually working as intended, even if ran on my machine locally, not remotely.   It does the same thing, but just as IWAM.  

I think that's clears it up more.   I'll see if my other ideas work.


Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question