Shell – System Function





Shell Function


Usage

The Shell function executes a program (.exe, .com, .bat, .doc, .txt, …).

The main usage of the Shell function is 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 loading before moving to the next step. The Shell line is automatically generated in the script if you use Recording mode; you can use its wizard by double-clicking Shell function in Insert statement window (press F4 to open Insert statement window).

Syntax

Shell (<program_name> [,<param>])

or

ret = Shell (<program_name> [,<param>])

Parameters

  • <program_name>: string, name of the executable module to be run with any parameters.
  • <param>: 1 for normal execution, 2 for minimized execution, 3 for maximized execution.

Return Value

ret, numeric return code. When the program has been launched successfully, the function returns 0; otherwise, use this return code for Error Handling.

Remarks

IMPORTANT: If <program_name> contains a space, you must surround it with the double-quote character CHR$(34). For example:

Shell(chr$(34)+"C:\\program files\\accessories\\mspaint"+chr$(34))

If the path contains spaces, you must surround it with CHR$(34). For example:

Shell(chr$(34)+"C:\\program files\\accessories\\mspaint"+chr$(34)+" "+chr$(34)+"C:\\program files\\accessories\\test.bmp"+chr$(34))

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\\wintask\\bin\\taskexec.exe"+chr$(34)+" "+chr$(34)+"c:\\program files\\wintask\\scripts\\myscript.rob"+" "+chr$(34)+"param1"+chr$(34)+" "+chr$(34)+param2$+chr$(34))

Note the use of CHR$(34) for the ASCII character code ".

See Also

Command$, 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)