• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

Running bat files

How do you get a bat file to run?
0
jjeva
Asked:
jjeva
1 Solution
 
dabelleiCommented:
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
 
jjevaAuthor Commented:
I'm pretty new, and didn't understand half of it, just give me the code. I'll probably understand it then
0
 
ajmendesCommented:
Hi,
try this code:

Dim i As Variant

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

Bye.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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

Bye.
0
 
ajmendesCommented:
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
 
mark2150Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now