Solved

Run a .bat with ASPExec

Posted on 2003-11-30
12
5,198 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:juststeve
Comment Utility
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
Comment Utility
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
Comment Utility
I'm betting it has something to do with IISv6.0...& am checking over in that area.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:funkmail
Comment Utility
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
Comment Utility
This would work for sure
0
 

Author Comment

by:juststeve
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

8 Experts available now in Live!

Get 1:1 Help Now