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
Solved

Run a .bat with ASPExec

Posted on 2003-11-30
12
5,216 Views
Last Modified: 2010-08-05
I'm working off Win2003 Server trying to execute a .bat file. It'd be nice to see the console output but not essential. I've downloaded and installed ASPExec from ServerObjects and have the following code that returns a 'ERROR: Could not create process':

<%
  Set Executor = Server.CreateObject("ASPExec.Execute")
  Executor.Application = "cmd"
  Executor.Parameters = "updatelog.bat"
  strResult = Executor.ExecuteDosApp
  Response.Write "<pre>" & strResult & "</pre>"
 %>


The batch file works if fired directly. IIS is set to execute Scripts & Executables. I've tried this with the IUSER having full perms with no difference in output. For giggles i even tried full perms on Everyone. No giggles and no joy.

Remember...Win2003 Server.

thankx
--steve...
0
Comment
Question by:juststeve
  • 4
  • 3
  • 2
  • +2
12 Comments
 

Author Comment

by:juststeve
ID: 9849582
I've found a couple other questions dealing with ASPExec that have led me to correct the path for calling the bat:

<%
  Set Executor = Server.CreateObject("ASPExec.Execute")
  Executor.Application = "cmd"
  Executor.Parameters = "/c d:\web\Root\updatelog.bat"
  Executor.ShowWindow = false
  strResult = Executor.ExecuteDosApp
  Response.Write "<pre>" & strResult & "</pre>"
%>


This still gets me the same error so I replace:
  strResult = Executor.ExecuteDosApp
with:
  Executor.ExecuteDosApp

This does not produce an error but also does not run the batch.
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9850745
I think you need to tell the Application object to run the exe, like this:

Executor.Application = "cmd.exe"
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9850759
Oh, yea you can also do away with the parameters object and just put the whole command in the application object.

Executor.Application = "cmd /c d:\web\Root\updatelog.bat"
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:juststeve
ID: 9850898
No joy to either suggestion but something interesting.

Orginally I mentioned that I didn't get any error when I replace:
  strResult = Executor.ExecuteDosApp
with:
  Executor.ExecuteDosApp

I've discovered that this will not fire the error:
  strResult = Executor.ExecuteDosApp
if the line that attempts to write the value of the var is commented out:
'  Response.write (strResult)
0
 
LVL 9

Accepted Solution

by:
TooKoolKris earned 250 total points
ID: 9851999
That's wierd, can't explain that other then to suggest that you double check to make sure there are no syntax errors anywhere. I don't see any in your code however. If you want to see the output to the console you can use a start /wait command to hold it open until your command is complete. For example if you wanted to watch all of your files being copied in the console window you would issue:

start /wait copy C:\test\*.* D:\test\

You can put the start /wait in from of any command you issue at a prompt. It's mostly used in batch files where you want each command to finish before the next one runs.
0
 

Author Comment

by:juststeve
ID: 9852034
I'm betting it has something to do with IISv6.0...& am checking over in that area.
0
 

Expert Comment

by:funkmail
ID: 9858272
Firstly, make sure you have given something like this

Set Executor = Server.CreateObject("ASPExec.Execute")
Executor.Application = "cmd /c c:\scripts\cards_mp.bat" //The script path
Executor.Parameters = "" //No need to specify anything
strResult = Executor.ExecuteDosApp

Then give full permission to IUSR & IWAM users on that particular directory.
Thats all required. But thats a security breach. What you can do is First try giving full permissions and then when it works remove the unwanted permissions like write etc.

Bye
S

0
 

Expert Comment

by:funkmail
ID: 9858282
This would work for sure
0
 

Author Comment

by:juststeve
ID: 9896634
I have to drop the hunt for this particular solution but i think there's enough good information here to leave in the archives... and Kris deserves points for effort.
0
 

Expert Comment

by:tleek
ID: 10146509
Hi,

I've had exactly the same problems with ASPEXEC on a new install of WinXP Pro. After burning the midnight oil, and tearing out most of my hair, I managed to get it working..

Thought I'd post a note with the things I did to fix it, in case any of these are useful to anyone.

checked 'Allow service to interact with desktop' for IIS Admin as well as WWW svcs
allowed IUSR_****** read access to cmd.exe and read/execute to target directory
turned _off_ script blocking in Norton AV 2003...

didn't need scripts and executables turned on, only scripts.

I need to set it up on a 2003 server tomorrow myself.

Tiff
0
 

Expert Comment

by:tleek
ID: 10146646
Sorry, remembered the other thing that was messing things up.

.NET must be installed _after_ IIS for it all to function properly, you can just reinstall if nec.

(I think this is not supposed to apply to server 2003 though)

Tiff
0
 

Expert Comment

by:gwilsonb
ID: 10596310
I tried CMD exec SSI includes and ServerObject's aspexec object but couldn't get either to work despite lots of trying. Perhaps both are difficult to get working after you've locked down IIS to make it more secure with something like Lockdown.

This worked however:

' show live server connections on an ASP page

dim ObjWshell, ObjCmd, strPResult
set ObjWshell = server.CreateObject("WScript.Shell")
set objCmd = objWShell.Exec("c:\utils\netstat -n")
strPResult = objCmd.StdOut.Readall()
Response.Write "<p><b>NetStat</b> Server Time: "& now
set objCmd = nothing
set ObjWshell = nothing
Response.Write "<font size=2>" & "<pre>" & 
      replace(strPResult,vbCRlf,"<br>") & "</pre>"

NB iusr_machinename (LOCAL machine a/c) MUST have RX permissions on the file you are calling (in this example I placed a copy of netstat in a directory and modified the permissions on it).
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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