ShellExecuteWait

Runs a program via the Windows ShellExecute command

Syntax:

ShellExecuteWait (program-name, params, directory, display mode, operation)

Parameters:

(s) program-name: the name of the desired .EXE, .COM, .BAT, .CMD file or almost any file with an associated application.

(s) params: optional parameters as required by the application.

(s) directory: current working directory (if applicable).

(i) display mode: @NORMAL, @ICON, @ZOOMED, @HIDDEN, @NOACTIVATE, or 0 for the default mode.

(i) operation; operation to perform on the specified file.

Returns:

(i) @TRUE on success and WIL is suspended; @FALSE on failure or WIL not suspended.

 

This function uses the Windows ShellExecute API to launch the specified file. The similar WIL ShellExecute function except that WinBatch or compiled script executable suspends processing until the application is closed.

"Operation" is the operation to perform on the file ("edit', "open", "print", "explore","find', "runas", etc.), which may but not always correspond to an available "verb" on the context menu for the file. This parameter may be case-sensitive. Specify a blank string "" for the file's default operation.

Note: If you use this function to launch a shortcut, and the shortcut points to an invalid path, Windows will display a "Missing Shortcut" dialog box asking if you wish to update the shortcut. This would not be suitable to use in unattended operation. Instead, you could use one of the Run.. functions to launch the shortcut, which would return an error #1932 if the shortcut could not be launched. This error can be trapped using the ErrorMode function.

Special Notes:

On Windows 8 and newer, if logged in as administrator, running WinBatch with full administrative execution level (default) and trying to run a process requesting AsInvoker, the process will be run with full Administrative execution level. This is due to the requirements implemented by the Windows OS.

Important: ShellExecuteWait is not always able to suspend the script or program calling the function even when the function is otherwise successful. This can happen when the actions specified by the function's parameters does not start a new process. Test the functions return value to detect when this is the case.    

Example 1:

;; View a webpage in the system default browser.
bRet = ShellExecuteWait('https://www.winbatch.com/download.html','','',@normal, '')
If bRet Then Message('ShellExecute','Paused this script.')
Else Message('ShellExecute','Did NOT paused this script.')
Example 2:

Folder = Environment('temp')
ShellExecuteWait(Environment('comspec'), '/c dir *.exe>':Folder:'/temp.txt','',@hidden, '')
ShellExecuteWait('Notepad.exe', Folder:'/temp.txt','',@normal, '')
FileDelete(Folder:"/temp.txt")
See Also:

RunShell, RunWithLogon, ShellExecute, RunWait