IShellDispatch2.ShellExecute method

Performs a specified operation on a specified file.


iRetVal = IShellDispatch2.ShellExecute(
  [ vArguments ],
  [ vDirectory ],
  [ vOperation ],
  [ vShow ]

IShellDispatch2.ShellExecute( _
  ByVal sFile As BSTR, _
  [ ByVal vArguments As Variant ], _
  [ ByVal vDirectory As Variant ], _
  [ ByVal vOperation As Variant ], _
  [ ByVal vShow As Variant ] _
) As Integer


sFile [in]

Type: BSTR

A String that contains the name of the file on which ShellExecute will perform the action specified by vOperation.

vArguments [in, optional]

Type: Variant

A string that contains parameter values for the operation.

vDirectory [in, optional]

Type: Variant

The fully qualified path of the directory that contains the file specified by sFile. If this parameter is not specified, the current working directory is used.

vOperation [in, optional]

Type: Variant

The operation to be performed. This value is set to one of the verb strings that is supported by the file. For a discussion of verbs, see the Remarks section. If this parameter is not specified, the default operation is performed.

vShow [in, optional]

Type: Variant

A recommendation as to how the application window should be displayed initially. The application can ignore this recommendation. This parameter can be one of the following values. If this parameter is not specified, the application uses its default value.

Value Meaning
Open the application with a hidden window.
Open the application with a normal window. If the window is minimized or maximized, the system restores it to its original size and position.
Open the application with a minimized window.
Open the application with a maximized window.
Open the application with its window at its most recent size and position. The active window remains active.
Open the application with its window at its current size and position.
Open the application with a minimized window. The active window remains active.
Open the application with its window in the default state specified by the application.



This method is implemented and accessed through the Shell.ShellExecute method.

This method is equivalent to launching one of the commands associated with a file's shortcut menu. Each command is represented by a verb string. The set of supported verbs varies from file to file. The most commonly supported verb is "open", which is also usually the default verb. Other verbs might be supported by only certain types of files. For further discussion of Shell verbs, see Launching Applications or Extending Shortcut Menus.

This method is not currently available in Microsoft Visual Basic.


The following examples show the use of ShellExecute to open Notepad. Usage is shown for JScript and VBScript.


<script language="JScript">
    function fnShellExecuteJ()
        var objShell = new ActiveXObject("shell.application");
        objShell.ShellExecute("notepad.exe", "", "", "open", 1);


<script language="VBScript">
    function fnShellExecuteVB()
        dim objShell

        set objShell = CreateObject("shell.application")

        objShell.ShellExecute "notepad.exe", "", "", "open", 1

        set objShell = nothing
    end function


Requirement Value
Minimum supported client
Windows 2000 Professional, Windows XP [desktop apps only]
Minimum supported server
Windows Server 2003 [desktop apps only]
Shell32.dll (version 5.0 or later)