Name

Shell Function

Class

Microsoft.VisualBasic.Interaction

Syntax

Shell(pathname[,style][, Wait][, Timeout] )
pathname (required; String)

Name of the program to execute

style (optional; AppWinStyle enumeration)

The style of window and whether it receives the focus; see Section

Wait (optional; Boolean)

Boolean indicating whether to wait for the pathname application to finish execution before continuing execution of subsequent code

Timeout (optional; Integer)

If Wait is True, number of milliseconds to wait for the pathname application to terminate before the Shell function times out

Return Value

An Integer representing the Process ID, or 0

Description

Launches another application and, if successful, returns that application’s task ID

Rules at a Glance

  • pathname can include a drive letter. If a drive letter is not included in pathname, the current drive is assumed.

  • pathname can include a folder name. You can use either a fully qualified path (i.e., starting from the root directory) or a relative path (i.e., starting from the current directory). If the folder name is not included in pathname, the current folder is assumed.

  • pathname can include any command-line arguments and switches required by the application. For example:

    Shell("notepad.exe c:\data.txt", AppWinStyle.NormalFocus)

    launches Notepad, which loads the file data.txt.

  • Visual Basic includes the following intrinsic constants for setting the style argument:

    AppWinStyle.Hide Value: 0

    New application window is hidden

    Focus: New application ...

Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.