Solved

How to execute a bat file with ASP

Posted on 2001-06-05
16
566 Views
Last Modified: 2007-12-19
How can I execute a bat file with asp? Say I have folder c:\file\Stop.bat can I execute this with some code and a simple link to it?
0
Comment
Question by:Dsys
  • 7
  • 5
  • 2
  • +2
16 Comments
 
LVL 4

Expert Comment

by:epeele
ID: 6155682
You can use the Windows Scripting Host to do this:

Set x = Server.CreateObject("WScript.Shell")
x.Run "c:\prog.exe 1"
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6155683
using the component aspexec (from www.serverobjects.com)
0
 

Author Comment

by:Dsys
ID: 6155823
I tried this:

<a href="ExeStart.asp"> ExeStart.asp</a>

<%
  Set x = Server.CreateObject("WScript.Shell")
  x.Run "C:\jsdk2.1\startserver.bat"
%>

no errors just does not start the bat file.

I will read about www.serverobjects.com shortly.
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6156040
for this

Set x = Server.CreateObject("WScript.Shell")
 x.Run "C:\jsdk2.1\startserver.bat"


you'll need to give the IUSR read permissions on the batch file ..

but you better try the free component
0
 

Author Comment

by:Dsys
ID: 6157808
OK I can try this ASP component.

It says:
Installation: To use this ASP component move the DLL into a subdirectory (like \winnt\system32 for NT or \windows\system for Win95) and type

   regsvr32 aspexec.dll

You MUST go into control panel/services/world wide web publishing service and turn Allow Service to Interact with Desktop on to use this component if you run IIS as a service.

Does it matter where I place the DLL? This command  regsvr32 aspexec.dll will this register it as a service and will I see it appear in my services then?
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6159632
You can store it anywhere.. but better where they said..
and no, it's not a service, it is a component.. a program that remains loaded in the memory..
0
 

Author Comment

by:Dsys
ID: 6163449
OK i have it installed and ran the demos of this they work I guess.

Here is what the examples show.

<%
  Set Executor = Server.CreateObject("ASPExec.Execute")

  rem ***********************************************
  rem * I'm not feeling very original tonight so
  rem * let's just execute notepad and then close it
  rem * out to verify the Wait portion works...
  rem ***********************************************

  Executor.Application = "notepad.exe"
  Executor.Parameters = "c:\autoexec.bat"
  Executor.TimeOut = 9000
  Response.Write "Attempting to execute " & Executor.Application & "<br>"

  rem results of this method are the results of GetLastError
  intResult = Executor.ExecuteWinAppAndWait
  if intResult = 0 then
    Response.Write "Execution successful"
  else
    Response.Write "The result of this call was: " & intResult
  e
%>

Do I simply substitute :

  Executor.Application = "startserver.bat"
  Executor.Parameters = "C:\jsdk2.1\"

to execute my bat file? I tried this but the bat file does not execute...
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6163529
what's the error?

Executor.Application = "C:\jsdk2.1\startserver.bat"

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Dsys
ID: 6166076
There is no error from this it simple does not run the bat file. It shows a page.

<%
  Set Executor = Server.CreateObject("ASPExec.Execute")
  Executor.Application = "C:\jsdk2.1\startserver.bat"
  Executor.ShowWindow = True
  Response.Write "Attempting to execute " &
  Executor.Application & "<br>"
  strResult = Executor.ExecuteWinApp
  Response.Write "The result of this call was: " & strResult
%>

0
 

Author Comment

by:Dsys
ID: 6166114
This is what is in startserver.bat

@echo off
rem $Id: startup.bat,v 1.8 1999/04/09 19:50:34 duncan Exp $
rem Startup batch file for servlet runner.

rem This batch file written and tested under Windows NT
rem Improvements to this file are welcome

if "%CLASSPATH%" == "" goto noclasspath

rem else
set _CLASSPATH=%CLASSPATH%
set CLASSPATH=server.jar;servlet.jar;classes;%CLASSPATH%
goto next

:noclasspath
set _CLASSPATH=
set CLASSPATH=server.jar;servlet.jar;classes
goto next

:next
rem echo Using classpath: %CLASSPATH%
start java com.sun.web.shell.Startup %1 %2 %3 %4 %5 %6 %7 %8 %9

rem clean up classpath after
set CLASSPATH=%_CLASSPATH%
set _CLASSPATH=

Once is it executed it should stay up in a command window.
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6167036
set an admin account to run the aspexec
0
 

Author Comment

by:Dsys
ID: 6167253
I log in as the admin. How do I do set an admin account to run it? I did this: regsvr32 aspexec.dll and I installed logged in as the admin.
0
 
LVL 3

Expert Comment

by:yas022100
ID: 6699576
You may want to set it up on COM+ environement (Component Service) where you can set one of the properties to run as Administrator.

0
 

Author Comment

by:Dsys
ID: 6707264
Yas,

 Would this run on a hourly basis? Execution of the stopserver.bat is easy but once tomcat is tunred off it can no longer process request which makes sence. Basically it should execute startserver.bat if tomcat.exe is not running.

 Never have used Com+. Could you explain how would this work.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6956387
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20068272.html
http://www.experts-exchange.com/questions/Q.20068448.html
http://www.experts-exchange.com/questions/Q.20073560.html
http://www.experts-exchange.com/questions/Q.20076023.html
http://www.experts-exchange.com/questions/Q.20129982.html
http://www.experts-exchange.com/questions/Q.20215566.html
http://www.experts-exchange.com/questions/Q.20287052.html
http://www.experts-exchange.com/questions/Q.20289705.html




*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 7118827
Inconclusive, 20 points refunded, item closed by moving to our PAQ at zero.
Moondancer - EE Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

19 Experts available now in Live!

Get 1:1 Help Now