Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: ,

How to run a .bat file with VBScript ?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-10-2008
troy's Avatar
Member
 
Join Date: Feb 2006
Posts: 67
How to run a .bat file with VBScript ?

I want to run a .bat file from VB, can anyone help me out? I have looked for a long time for it and found nothing. Thanks in advance
Reply With Quote
  #2  
Old 17-10-2008
Expertz's Avatar
Member
 
Join Date: Dec 2007
Posts: 932
All I do in my VB program is this to run a batch file, might work or not:
Code:
 'send e-mail
    Shell strEmailPath & strEmailBAT
Below are lines from the ini file that I use during initialization to set strEmailPath & strEmailBAT.
########## email batch file location
EMAILPATH=C:\jazz\copydata\email\
EMAILBAT=emailerr.bat

Hope this helps
Reply With Quote
  #3  
Old 17-10-2008
JAMES_911's Avatar
Member
 
Join Date: Dec 2007
Posts: 722
If you're using vbscript, you can do this:

dim shell
set shell=createobject("wscript.shell")
shell.run "batchfile.bat"
set shell=nothing


so you should be able to call the same automation object in VB.

for VB.NET this will work:

using System;

namespace Learn
{
class cmdShell
{
[STAThread]
static void Main(string[] args)
{
Declare New Process
System.Diagnostics.Process proc;

Run test.bat from command line.

proc = System.Diagnostics.Process.Start("C:\\test.bat");

Waits for the process to end.

proc.WaitForExit();
}
}
}



in VB you might be able to import the shell exec api:

Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

you can then use shellexecute to run "mybat.bat"

see this page for more info:

http://custom.programming-in.net/art...f=ShellExecute
Reply With Quote
  #4  
Old 17-10-2008
Gusgr8's Avatar
Member
 
Join Date: Jun 2006
Posts: 448
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
Reply With Quote
  #5  
Old 17-10-2008
Team Leader's Avatar
Member
 
Join Date: Dec 2007
Posts: 833
Just run it like any other executable.

Sample:

----------------
echo this is a batch file
c:
cd\temp
something.vbs
REM note the .vbs above is optional
Echo Batch file is over
-----------------
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "How to run a .bat file with VBScript ?"
Thread Thread Starter Forum Replies Last Post
What happens when you drag and drop a file on top of a vbscript Dharmavira Software Development 2 01-06-2009 10:00 PM
How can i drag and drop another file on top of the VBScript file Dharmesh Arora Software Development 2 01-06-2009 09:53 PM
Issues when launching a vbscript file from hta interface file Hari Server Scripting 3 14-04-2009 11:01 PM
!!! vbScript Output to an HTML File !!!!! Ahmed H. Habashy Server Scripting 2 28-11-2006 02:49 PM
VBscript to apply .reg file Damo_Suzuki Customize XP 7 04-05-2006 07:19 PM


All times are GMT +5.5. The time now is 04:51 AM.