Solved

How to execute a bat file with ASP

Posted on 2001-06-05
16
572 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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
 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Response.Flush in Classic ASP causing TIME_WAIT ports 9 100
how to hide hide popup page refresh second time? 10 125
Import csv files to MS SQL 5 81
Time Conversions...both ways 2 16
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

778 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