System.Shell.execute Method

Launches an application.

Syntax

retVal = System.Shell.execute(
  strFile,
  [ strArgs ],
  [ strDir ],
  [ strOperation ]
)

Parameters

  • strFile [in]
    BSTR Sets String that specifies a UNC path to an executable file, a filename, or a URL.
  • strArgs [in, optional]
    BSTR Sets If strFile specifies an executable file then String specifies the parameters to be passed to the application. For example, a UNC path such as System.Gadget.path + "\\MyFile.Txt". Note  If strFile specifies a filename or URL, strArgs is unneccessary and should be blank, null, or an empty string.
  • strDir [in, optional]
    BSTR Sets String that specifies the UNC path for the default (working) directory of the executable file.
  • strOperation [in, optional]
    BSTR Sets String that specifies the action (or Windows Shell verb) to be performed. The set of available verbs depends on the particular file or folder.
    Value Meaning
    edit

    Opens the file specified by strArgs for editing.

    explore

    Opens the folder specified by strDir for exploring.

    find

    Opens the folder specified by strDir for searching.

    open

    Opens the file specified by strArgs.

    print

    Prints the file specified by strArgs on the default printer.

     

Return Value

HRESULT

If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

Supplying a path to a filename (with extension) or a URL for strFile will launch the default application associated with that file extension and load the filename specified.

Note  Alternatively, a path to a known application .exe can by supplied for strFile while strArgs, strDir, and strOperation are used to specify the rest of the file information.

strArgs, strDir, and strOperation can be assigned values in combination as required.

UNC paths should escape special characters with a '\'.

Examples

The following example demonstrates how to launch a URL.

System.Shell.execute("http://www.microsoft.com");

The following example demonstrates how to open a text file in the default application and in Notepad.

System.Shell.execute(System.Gadget.path + "\\MyFile.txt");
System.Shell.execute("Notepad.exe", "MyFile.Txt", "C:\\Users\\MyName\\", "open");

The following example demonstrates how to print a text file.

System.Shell.execute(System.Gadget.path + "\\MyFile.txt", null, null, "print");

Requirements

Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
IDL Sidebar.idl
DLL Sidebar.Exe version 1.00 or later

See Also

System.Shell

 

 

Send comments about this topic to Microsoft

Build date: 2/24/2010

Build type: SDK