Solved

Run a .bat with ASPExec

Posted on 2003-11-30
12
5,222 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
[X]
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
  • 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
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

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP server side get value 15 47
Call a function within the ASP code 4 26
Html CheckBox obtain Its Value 5 37
Boolean 13 24
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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