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
  • 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.
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.


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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now