Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleStart another program using Shell
KeywordsShell, start, execute
CategoriesWindows
 
Use the Shell statement. The first parameter is the full path to the executable you want to start. The second is the mode in which the new program should start. This mode should be one of the following values:

ParameterMeaning
vbHideThe new application is invisible and does not appear in the task bar. This option is rarely used.
vbMaximizedFocusThe new application is maximized and gets the input focus.
vbMinimizedFocusThe new application is minimized and gets the input focus. While this seems like one of the less useful modes, it is the default if you leave the parameter off.
vbMinimizedNoFocusThe new application is minimized and does not get the input focus. This is more common than vbMinimizedFocus.
vbNormalFocusThe application starts normally and gets the focus. This is probably the most commonly used setting.
vbNormalNoFocusThe application starts at normal size but does not get the focus.

In this program, the TextBox txtProgram gives the path to the program and the ComboBox cboShellStyle selects the program's run style.

 
' Start the program.
Private Sub cmdRun_Click()
    On Error GoTo ShellError

    Select Case cboShellStyle.Text
        Case "vbHide"
            Shell txtProgram.Text, vbHide
        Case "vbMaximizedFocus"
            Shell txtProgram.Text, vbMaximizedFocus
        Case "vbMinimizedFocus"
            Shell txtProgram.Text, vbMinimizedFocus
        Case "vbMinimizedNoFocus"
            Shell txtProgram.Text, vbMinimizedNoFocus
        Case "vbNormalFocus"
            Shell txtProgram.Text, vbNormalFocus
        Case "vbNormalNoFocus"
            Shell txtProgram.Text, vbNormalNoFocus
    End Select
    Exit Sub

ShellError:
    MsgBox "Error Shelling file." & vbCrLf & _
        Err.Description, vbOKOnly Or vbExclamation, _
        "Error"
    Exit Sub
End Sub
 
See also:
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated