Solved

Running bat files

Posted on 1998-10-29
6
415 Views
Last Modified: 2010-04-30
How do you get a bat file to run?
0
Comment
Question by:jjeva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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