Hi everyone,

Batch example: start /wait executable.exe

I've been using this method with batch files, this time i would like to
use something similar in Visual Basic 6, i tried to replace this method
using Do While Loop, Do Until... Loop Statement, etc. but still can't find
a better way to do it. now here is what i am after, i am working in a code
that execute a file, then when that program close or either way i close it,
then the next executable asigned to the task will lunch. how can i do this
in my project? any help will be very appreciate, thanks in advance.

Dani AI

Generated

A short expert summary for the thread: pointed you to useful references and found the CodeGuru approach solved the immediate problem because it follows the standard Win32 pattern — start the child, obtain a process handle, then wait for that handle to be signaled. Below are safe, practical options and the common pitfalls to watch for.

Preferred, robust option — CreateProcess + WaitForSingleObject: create the child with CreateProcess so you receive a PROCESS_INFORMATION structure (it contains hProcess), then call WaitForSingleObject(hProcess, INFINITE) to wait for exit. This gives the most control (startup flags, working directory, handles) and is the pattern Microsoft documents for synchronizing with a launched process. (learn.microsoft.com)

Easy alternatives — ShellExecuteEx or Shell+OpenProcess: call ShellExecuteEx with SEE_MASK_NOCLOSEPROCESS to get hProcess directly (if the shell actually launches a new process), or use VB’s built‑in Shell (which returns a task/process id) and call OpenProcess(SYNCHRONIZE, FALSE, pid) to get a handle you can pass to WaitForSingleObject. Both approaches are widely used when you don’t need the finer control of CreateProcess. (learn.microsoft.com)

Pitfalls and tips: blocking a UI thread with a plain Wait will freeze the interface — use MsgWaitForMultipleObjects (or perform the wait on a worker thread / timer loop that pumps messages) so the app stays responsive. Also remember to CloseHandle the process handle when done to avoid leaks. For monitoring whole process trees (child processes spawned by the child) consider job objects; simple waits track only the single process handle you opened. (learn.microsoft.com)

If more specific VB6 code is needed (declarations, SYNCHRONIZE access, safe message‑pump loop, or Job‑object notes), post the exact scenario (console vs GUI, need to capture output, elevated launch), and a small, targeted snippet can be provided.

Recommended Answers

All 2 Replies

Hi Veena,

I tried the code from Visual Basic Helper, but is not that accurate.
But WooW! the one from codeguru forum WooW! is just what i needed!!!
Thanks a million Veena ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.