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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Batch file with VBScript from IE 1

Status
Not open for further replies.

M626

Programmer
Mar 13, 2002
299
Is it possible to run a batch file using VBS from IE. I am new to VBS so any links or example would be very useful. I want to take a directory of all batch files and have a web page where each script can be selected with a check boxes then run them with a command button.
 
Yes, you can do this with the Shell.

Set WSHShell = CreateObject("Wscript.Shell")
WSHShell.Run ("c:\myBatfile.bat")

I hope you find this post helpful.

Regards,

Mark
 
so how would i use that and call it from an HTML page?
 
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<% 
Set WSHShell = CreateObject("Wscript.Shell")
WSHShell.Run ("c:\myBatfile.bat") 
%>

<html>
<title>Sample</title>
<body>
Blah Blah
</body>
</html>

I hope you find this post helpful.

Regards,

Mark
 
I tried to add this code to a case statement in vbscript and I understand that the space between Program and Files is causing a problem. I'm not sure how to fix it. Any ideas?

Todd

Code:
Dim WShell
Set WShell = CreateObject("Wscript.Shell")
WShell.Run "C:\Program Files\ARINC\AIM\PACIS\MBTA\DBS\restoreGUItables.bat"
Set WShell = Nothing
 
Just add DOUBLE Quotes for the line

WShell.Run """C:\Program Files\ARINC\AIM\PACIS\MBTA\DBS\restoreGUItables.bat"""

The outside set of quotes is for the wshell.run parameters, the double insides are literals.

Phil Gordemer
 
this isnt explicitily for " " white spaces but is good practive,,,

replace "c:\program files... with

WshShell.Run "%programfiles%\.....", 1, True

that way it will work on any machine no matter where program files are located/

if you want to work with strings then use

WshShell.ExpandEnvironmentStrings(strToMod)
 
So, I've decided to use this statement and test my code.

Code:
Dim WShell
Set WShell = CreateObject("Wscript.Shell")
WShell.Run """C:\Program Files\ARINC\AIM\PACIS\MBTA\DBS\restoreGUItables.bat"""
Set WShell = Nothing

The page posts like it should, but the batch file never executes. Here is the code in the batch file:

Code:
echo MBTAPACIS/MBTAPACIS@ORCL9 > restoreGUItables.sql
echo SET SERVEROUTPUT ON; >> restoreGUItables.sql
echo @"%MBTAPACIS_DB%\DBS\restore_gui_tables.sql"; >> restoreGUItables.sql
echo COMMIT; >> restoreGUItables.sql
type restoreGUItables.sql | sqlplus -s
del restoreGUItables.sql;

Here is the SQL script it calls:
Code:
spool MBTAPACIS_restoreguitables.lst

--
-- Drop Tables
--
@"%MBTAPACIS_DB%\DBS\drop_gui_tables.sql"

--
-- Create Tables
--
@"%MBTAPACIS_DB%\DBS\create_gui_tables.sql"

--
-- Populate Tables
--
@"%MBTAPACIS_DB%\DBS\populate_gui_tables.sql"

--
--  Re-compile package bodies...
--
@"%MBTAPACIS_DB%\DBS\compile_package_bodies.sql"

spool off;
commit;

I even set the IUSER_MACHINENAME account with full access to my DBS folder. Any ideas to get the batch script to fire off the sql?

Todd
 
Dim WShell
Set WShell = CreateObject("Wscript.Shell")
WShell.Run """C:\Program Files\ARINC\AIM\PACIS\MBTA\DBS\restoreGUItables.bat"""
Set WShell = Nothing


Try this out for size. Create an ASP page. With this code

<html>
<%
Dim WSHell
Set WSHell = Server.CreateObject("Wscript.Shell")
WShell.Run "C:\program" & " Files\ARINC\AIM\PACIS\MBTA\DBS\restoreGUItables.bat"
Set WShell = Nothing
%>

<body>

This is the body you can say what you want here.

</body>
</html>

If you look at the code you will see a space between the " and Files. Any time you have a space in a path or string you can break it up by quotating the first part then put a space either at the end of this quotation or at the beginng of your next quotation but do either of these by putting the space in the quotation mark. Don't forget to put the & in between the two quoation strings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top