Shell Function


Shell Function

Class

Microsoft.VisualBasic.Interaction

Syntax

     Dim result As Integer = Shell(pathName[, style[, wait[, timeout]]]) 


pathName (required; String)

The name and path of the program to start.


style (optional; AppWinStyle enumeration)

The style of the new application's window and whether it receives the focus automatically when starting up. One of the following Microsoft.VisualBasic.AppWinStyle enumeration values:

Value

Description

Hide

The new application window is hidden and does not receive the focus.

NomalFocus

The new application window is displayed normally and immediately receives the focus.

MinimizedFocus

The new application window is minimized but does receive the focus.

MaximizedFocus

The new application window is maximized and immediately receives the focus.

MinimizedNoFocus

The new application window is minimized and does not receive the focus.

MaximizedNoFocus

The new application window is maximized but does not receive the focus.


If omitted, the default value is MinimizedFocus.


wait (optional; Boolean)

Indicates whether to wait for the pathName application to finish execution before continuing execution of subsequent code (true) or not (False). If omitted, the default value is False.


timeout (optional; Integer)

If wait is true, this argument indicates the number of milliseconds to wait for the pathName application to terminate before the Shell function times out. If omitted, the default value is -1, which indicates that the Shell function should never time out.

Description

The Shell function launches another application and, if successful, returns that application's task or process ID.

Usage at a Glance

  • pathName can be a relative or absolute path on a local or remote drive.

  • pathName can include, after the application name, any command-line arguments and switches required by the application. For example:

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

    launches Notepad, which then loads the file c:\data.txt.

  • If the application named in pathName executes successfully, Shell returns the Windows task ID of the program. (The task ID is also known as the process ID (PID), a unique 32-bit value used to identify each running process.) This value can be used as an argument to the AppActivate procedure. The process ID is also required by a number of Win32 API functions.

  • If the application named in pathName fails to execute, a runtime error occurs.

  • The file launched by Shell must be executable. That is, it must be a file with an extension that is .EXE or .COM (an executable file), .BAT (a batch file), or .PIF (a DOS shortcut file). You cannot use Shell to launch web pages or other URL-based resources. It also cannot be used to launch applications by association. Using "MyDocument.txt" for pathName will not start Notepad.

  • Wait determines whether the Shell function operates synchronously (true) or asynchronously (False). The default is False; control returns immediately to the application, and the code continues executing as soon as the process ID is known. If TRue, the Shell function returns only when the pathName application is closed or, if timeout is not -1, when the timeout period has expired.

  • If the pathName application exits before the Shell function returns, the return value of Shell will be 0.

  • Setting wait to true and leaving timeout at its default value of -1 creates the possibility that control will never return from the pathName application to the initiating application.

Version Differences

The wait and timeout arguments are new to .NET. They are not supported by VB 6.

See Also

AppActivate Procedure




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net