Waiting for a shelled process to terminate
By: Microsoft Corporation Date: 28/07/2001



813 bytes

Download now!

Executing the Shell function in a Visual Basic for Windows program starts another executable program asynchronously and returns control to the Visual Basic application. This shelled program continues to run independently of your application until the user closes it.

The Win32 API has integrated functionality that enables an application to wait until a shelled process has completed. To use these functions, you need a handle to the shelled process. The easiest way to achieve this is to use the CreateProcess API function to launch your shelled program rather than Visual Basic's
Shell function.

This function is a substitution of Shell that actually waits for the shelled process to terminate: the shelled process can be any Windows 16-bit or 32-bit application and any DOS application.




CommandLine: complete path and filename of a EXE, COM or BAT file

Type of data

CommandLine: String


A long value returned by the shelled application itself.


Run Notepad and wait until it closes.

Dim RetVal As Long
RetVal = ExecCmd("C:\Windows\Notepad.Exe")
MsgBox "Process Finished, Exit Code " & RetVal

The message box will not show up until you close Notepad.

The function is contained in a module. You can include it in any program of yours.

Click Here!

Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: www.inwind.it