BATCH FILE EXECUTION 
Author Message
 BATCH FILE EXECUTION

I a executing for example 300 batch files from my VB program that should
execute one at a time and in this case the application opens 300 sessions of
ms-dos prompt to run every batch file.  I have somehow beat this problem by
using GetWindow text api and Findwindow handles to try and close every
window that has finished running but I am not 100% successful.

This is what I do:

I open a session using the shell command.
Then I do Findwindow for the handle and close that handle using PostMessage.
I know this is correct, because i run a DEBUG and it works fine.
BUT....................

When I run 300 batch files consecutively without debugging,  it seems as
though the execution of the code is faster than the API call itself and it
skips over closing ms-dos sessions and i'm left with many windows open which
is not what I want.

Any ideas? What should I do?



Mon, 21 Jan 2002 03:00:00 GMT  
 BATCH FILE EXECUTION
Hi!

Check out Shell32.zip at http://www.mvps.org/vb/samples.htm.  This includes a
number of methods for shelling and waiting for a program to finish.  One of
these, ShellAndClose, appears to me to be particularly suited to your situation.

John....

Quote:

> I a executing for example 300 batch files from my VB program that should
> execute one at a time and in this case the application opens 300 sessions of
> ms-dos prompt to run every batch file.  I have somehow beat this problem by
> using GetWindow text api and Findwindow handles to try and close every
> window that has finished running but I am not 100% successful.

> This is what I do:

> I open a session using the shell command.
> Then I do Findwindow for the handle and close that handle using PostMessage.
> I know this is correct, because i run a DEBUG and it works fine.
> BUT....................

> When I run 300 batch files consecutively without debugging,  it seems as
> though the execution of the code is faster than the API call itself and it
> skips over closing ms-dos sessions and i'm left with many windows open which
> is not what I want.

> Any ideas? What should I do?



Mon, 21 Jan 2002 03:00:00 GMT  
 BATCH FILE EXECUTION
Try something like this ...

   RunShell "cmd.exe /c dir /b /s c:\winnt > d:\w.txt"

Private Sub RunShell(cmdline As String)

  Const PROCESS_QUERY_INFORMATION = &H400
  Const STATUS_PENDING = &H103&

  Dim hProcess As Long
  Dim ProcessId As Long
  Dim exitCode As Long

  ProcessId = Shell(cmdline, vbNormalFocus)  'can be vbHide
  hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)

  Do

      Call GetExitCodeProcess(hProcess, exitCode)

  Loop While exitCode = STATUS_PENDING

  Call CloseHandle(hProcess)

  MsgBox "The Shelled process has ended."

End Sub

You can grab the APIs from the API viewer. Just set up the RunShell command
passing the filenames of the batch files.

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/


| I a executing for example 300 batch files from my VB program that should
| execute one at a time and in this case the application opens 300 sessions
of
| ms-dos prompt to run every batch file.  I have somehow beat this problem
by
| using GetWindow text api and Findwindow handles to try and close every
| window that has finished running but I am not 100% successful.
|
| This is what I do:
|
| I open a session using the shell command.
| Then I do Findwindow for the handle and close that handle using
PostMessage.
| I know this is correct, because i run a DEBUG and it works fine.
| BUT....................
|
| When I run 300 batch files consecutively without debugging,  it seems as
| though the execution of the code is faster than the API call itself and it
| skips over closing ms-dos sessions and i'm left with many windows open
which
| is not what I want.
|
| Any ideas? What should I do?
|
|



Mon, 21 Jan 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Batch file execution from VB Application

2. Batch file execution from VB Application

3. Batch file execution from VB Application

4. Help with Batch file execution

5. Help with Batch file execution

6. Batch file execution from VB Application

7. Batch Execution in MSAccess

8. Batch Execution in MSAccess

9. DOS Batch File to Copy Files from an Access Application

10. Bad Command or File name when Shelling DOS Batch File

11. need batch file way to make Word97 convert a file

12. file compare inside a batch file

 

 
Powered by phpBB® Forum Software