Shell and Wait with Terminate, VB 6 Version - December 1998

If you download this tip please consider making a modest donation of a $1.00 or more.

Visual Basic can be launched in the 'background'. This is especially useful when compiling one or more applications with different conditional compilation arguments [see: VB6's Make Tab (Project Properties Dialog Box) and Command Line Arguments]. I have in the past used the 'standard' Shell command to launch VB. However, there are times when it would be great to wait for the compile to finish before starting the next one. And it would be nice if, once launched, VB could be terminated. I found a couple API's that allow me to accomplish this goal. So this becomes the tip-of-the-month.

2002/10/15 - I converted the function for VB.Net. Click here to view the VB.Net version.

Demo Program

demo.gif (3873 bytes)

The VB6 demo program.


info.gif (6484 bytes)

This helpful information is displayed when you select menu Help/Info.

Sample Application

process.gif (1580 bytes)

This 'sample application' is launched when you click the 'Launch...' button from the demo program.
Click 'Stop' to terminate the sample application and return control to the demo program.

Waiting Message

wait.gif (1093 bytes)

This message [form] is displayed when the sample application is launched.
Click the 'red' button to terminate the sample application.


Module 'modShellAndWait.bas' contains the VB code that provides support for the ShellAndWait and ShellAndWaitTerminate functions. The functions:

Function Description
ShellAndWait Call this function to start the shell and wait process. Information used by the function is passed in a user defined type [structure], see below.
ShellAndWaitTerminate Call this function to terminate a shelled process.

Structure udtShellAndWait

Properties are passed to the functions in a user defined type [structure] udtShellAndWait. The properties are:

Property Type Description
sCommand String The command used by the shell operation.
bShellAndWaitRunning Boolean This shell and wait operation is 'running'.
bNoTerminate Boolean If true, no forced termination allowed [no DoEvents].
lMilliseconds Long If termination is allowed, interrupt this often [DoEvents this often]. 1000 is one second. Default is one second.
bLogFile Boolean Write entries into the log file.
sLogFile String Fully qualified name of the log file.
lMaxSize Long Maximum log file size before automatically deleting it and starting over, default is 20K
dStart Date Date/Time the process started.
dFinish Date Date/Time the process finished.
dDiff Date Date/Time difference.
bTerminated Boolean Set true if terminated by ShellAndWaitTerminate function.
dTerminated Date Date/Time if terminated.
tProcess Process_Information Standard Windows structure used by the APIs.
tStart StartupInfo Standard Windows structure used by the APIs.

Sample Log File

logfile.gif (4357 bytes)

Start, finish and duration, the shelled command and, if terminated, the termination time are captured in the file.

API's Used


Include in Your Application

You will need to add the following module to your application if you want to use these functions:

modShellAndWait.bas The routine described in this document.

Help Uses modConnectToWebSite

The demo program uses modConnectToWebSite.bas to display this page. You do not need to include it in your application. For details on the use of that module click here.

Download VB Code

Click here to download the VB 6 Source Code [34k]. Click here to download the VB.Net Source Code [27k].

If you download this tip please consider making a modest donation of a $1.00 or more.
If you download this tip please consider making a modest donation of a $1.00 or more.

Previous Tip   Tip Index   Next Tip


Updated 2010/01/03