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?
|
|