Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a batch file on server and get results

Status
Not open for further replies.

glebreck

IS-IT--Management
Nov 20, 2002
34
US
Here is what I am wanting to do.

I run a repliction software that replicates a Dbase from an AS400 to SQL. Sometimes the connection to the AS400 fails and I recieve a text message on my cell to let me know this. My next step is to start up my vpn and restart the service.

What I have done is create two batch files. One to stop the service and one to start it. What I want to do is call those batch files from an ASP page, have them run on the server, and return results if the stop or start has worked.

This way I can take care of this from any place.
Is this possible?

I am using IIS 6
 
Download this:
...comes with example code, one of which is below:

Code:
<html>
<head><title>ASPExec Test (ExecuteWinApp)</title><head>
<body bgcolor=white text=black>
<blockquote>
<H3>ASPExec ExecuteWinApp Test</H3>
<%
  Set Executor = Server.CreateObject("ASPExec.Execute")
  Executor.Application = "notepad.exe"
  Executor.Parameters = "c:\autoexec.bat"
  Executor.ShowWindow = True
  Response.Write "Attempting to execute " & Executor.Application & "<br>"
  strResult = Executor.ExecuteWinApp
  Response.Write "The result of this call was: " & strResult
%>
<p>If you do not see Notepad then it is possible that Notepad is running with a hidden window.
This could be caused by not having "Allow Service to Interact with Desktop" turned off in 
Control Panel/Services/World Wide Web Publishing Service or it could be that the version 
of IIS you are running is preventing the window from being displayed. Look in a task list
such as task manager, or use TList from the NT resource kit to see if Notepad is running.
<B>Note: All InetInfo managed services must have "Allow Service to Interact with Desktop"
turned on to see visible apps.</b>
</blockquote>
</body>
</html>

Never tried it, but seems like it'd work.
 
I have downloaded what you said and the examplke works fine. But when I change it for what I need.. nothing happens. No errors or anything. Here is my code...

<%
Set Executor = Server.CreateObject("ASPExec.Execute")
Executor.Application = "cmd.exe"
Executor.Parameters = "c:\batch\stop.bat"
Executor.ShowWindow = True
Response.Write "Attempting to execute " & Executor.Application & "<br>"
strResult = Executor.ExecuteWinApp
Response.Write "The result of this call was: " & strResult
%>
 
Hello glebreck,

To execute a bat file, you need to have a switch for %comspec%. You cannot spare it.
[tt]
Executor.Parameters = "[red]/c[/red] c:\batch\stop.bat"
[/tt]
regards - tsuji
 
Well i tried adding the /c to the code and the same thing still happens. The page displays like it worked, but when I go to the server nothing has happened. And I have tested the batch file seperatly and it does work.
Here is the code:
Set Executor = Server.CreateObject("ASPExec.Execute")
Executor.Application = "cmd.exe"
Executor.Parameters = "/c c:\batch\stop.bat"
Executor.ShowWindow = True
Response.Write "Attempting to execute " & Executor.Application & "<br>"
strResult = Executor.ExecuteWinApp
Response.Write "The result of this call was: " & strResult
 
As a side note, I can call notepad and have that work, but I think the problem is calling cmd!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top