Solved

Running bat files

Posted on 1998-10-29
6
396 Views
Last Modified: 2010-04-30
How do you get a bat file to run?
0
Comment
Question by:jjeva
6 Comments
 
LVL 2

Expert Comment

by:dabellei
ID: 1442361
simpiest way is to use the shell function  here the MSDN topics

Shell Function
     

Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.

Syntax

Shell(pathname[,windowstyle])

The Shell function syntax has thesenamed arguments:

Part Description
pathname Required; Variant (String). Name of the program to execute and any requiredarguments orcommand-line switches; may include directory or folder and drive.
windowstyle Optional. Variant (Integer) corresponding to the style of the window in which the program is to be run. If windowstyle is omitted, the program is started minimized with focus.


The windowstyle named argument has these values:

Constant Value Description
vbHide 0 Window is hidden and focus is passed to the hidden window.  
vbNormalFocus 1 Window has focus and is restored to its original size and position.
vbMinimizedFocus 2 Window is displayed as an icon with focus.
vbMaximizedFocus 3 Window is maximized with focus.
vbNormalNoFocus 4 Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus 6 Window is displayed as an icon. The currently active window remains active.


Remarks

If the Shell function successfully executes the named file, it returns the task ID of the started program. The task ID is a unique number that identifies the running program. If the Shell function can't start the named program, an error occurs.

Note   By default, the Shell function runs other programs asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed.

0
 

Author Comment

by:jjeva
ID: 1442362
I'm pretty new, and didn't understand half of it, just give me the code. I'll probably understand it then
0
 
LVL 1

Accepted Solution

by:
ajmendes earned 10 total points
ID: 1442363
Hi,
try this code:

Dim i As Variant

    i = Shell("C:\windows\command.com <Batch Filename>", vbNormalFocus)

Bye.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:ajmendes
ID: 1442364
Hi, it's me again
i'm sorry, but the answer i gave to you is wrong.

Bye.
0
 
LVL 1

Expert Comment

by:ajmendes
ID: 1442365
Hi, i'm back once more

Try this:
Dim i As Variant

    i = Shell("<Batch Complete Filename>", vbNormalFocus)

this will work.
Tell me if it did, and in that case i will repost this as an answer, OK?
Bye.

0
 
LVL 12

Expert Comment

by:mark2150
ID: 1442366
SHELL will work to run a batch file, but it won't wait for it to complete. For that you need the ExecCmd function. Open up the question and I'll post the code.

M

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

930 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

15 Experts available now in Live!

Get 1:1 Help Now