Search Tools Links Login

Best Shell & Wait (No API's!)

Makes it easy to perform a clean "Shell & Wait" where your applicatoin kicks off an external application and waits for it to return before continuing. Many shell & wait examples I have found tend to overdrive the proccessor in a loop or require you to make API calls. This one uses the Windows Script object to take advantage of it's built-in wait parameter on the .Run method...scripting's version of Shell.

Original Author: Matt Roberts


FileName - The name of the file you wish to run with any required switches included.


Should work on any Windows 98 machine. Others may need to get the newest VB service pack or install Windows Scripting Host ( This is also included in Internet Explorer 5. If you already have IE5, this will work and it will be included when you build your setup file for distribution.


True if the file was run and returned.
False if there was a file open or save error.
EXAMPLE: ShellAndWait ("notepad.exe c: emp eset.txt)

Side Effects

None - Will not block other applications or overdrive the proccessor.


Function ShellAndWait(FileName As String)
Dim objScript
On Error GoTo ERR_OpenForEdit
Set objScript = CreateObject("WScript.Shell")
' Open a file for editing in Notepad and wait for return.
'The second parameter (after the FileName) is the Display Mode (normal w/focus,
'minimized...even hidden. For more info visit:
' The third parameter is the "Wait for return" parameter. This should be set to
' True for the Wait.
ShellApp = objScript.Run(FileName, 1, True)
ShellAndWait = True
Exit Function
MsgBox Err.Description
GoTo EXIT_OpenForEdit
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 96 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.