Home > Language Reference > System Functions > Shell

Shell

The Shell function launches the specified program (.exe, .com, .bat, etc.).

Usage

Used to start an application or open a document in preparation to send actions to it (using SendKeys function to send keystrokes for instance). The Shell function includes an automatic synchronization and so waits for the application to have finished to load before moving to the next step. The Shell statement is automatically generated in the script if you use Recording mode; you can use too its wizard by double-clicking Shell function name in the Language pane of the WinTask x64 Editor window on the right (press F4 to display this pane if it is not displayed).

Syntax

ret = Shell(<application_name> [, 1|2|3])

Parameters

<application_name>. string, name of the application to launch (case insensitive), including its parameters if any (see remarks).

1|2|3. If 1, the application is opened at its standard size. If 2 the application is launched minimized. If 3, the application is opened at its maximum size.

Return value

ret, optional integer return value. If the application has been launched successfully, the return value is 0. If the function fails, the return value is a nonzero value (see System Functions Error Codes).

Remarks

If <application_name> contains a space, you must surround it with the double-quote character CHR$(34). For example:
Shell(Chr$(34)+"C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE"+Chr$(34),1)

If the application is launched with parameters and so the full command line includes spaces, you must surround it with CHR$(34). For example:
Shell(Chr$(34)+"C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE"+Chr$(34)+" "+Chr$(34)+"C:\Program Files (x86)\data\data.xlsx"+Chr$(34),1)

Shell wizard creates the necessary CHR$(34) so it is highly recommended to use the wizard.

The Shell function can be used to launch a new script inside the currently running script: a new instance of the runtime module TASKEXEC is then opened (see the Run function to launch a script from another). Here is an example:
Shell(chr$(34)+"c:\program files (x86)\wintask\bin\taskexec.exe"+chr$(34)+" "+chr$(34)+ "c:\program files (x86)\wintask\scripts\myscript.rob" +" "+chr$(34)+"param1"+chr$(34)+" "+chr$(34)+param2$+chr$(34) )
Note again the use of CHR$(34) for the ASCII character code.

See also

ShellWait
Run

Examples

Shell("c:\winword\winword.exe c:\worddocs\my_doc.doc", 1)

Result=Shell("c:\worddocs\my_doc.doc", 1)

Shell( my_exe$, 2)