Showing posts with label Open Program. Show all posts
Showing posts with label Open Program. Show all posts

Saturday, February 11, 2017

VBScript Open Another Program And Wait Until Closed

VBScript is a scripting language to manage computer developed by Microsoft. Below is a code snippet to open an external program suppose named "firefox.exe" and wait until firefox closed. Script will not be execute further statements until firefox closed. 

Dim objShell

ShowOption = 1
WaitUntilClose = True

Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run """C:\Program Files\Mozilla Firefox\firefox.exe""", ShowOption, WaitUntilClose
Set objShell = Nothing

'ShowOption
'0 Hide the window (and activate another window.)
'1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time. 
'2 Activate & minimize. 
'3 Activate & maximize. 
'4 Restore. The active window remains active. 
'5 Activate & Restore. 
'6 Minimize & activate the next top-level window in the Z order. 
'7 Minimize. The active window remains active. 
'8 Display the window in its current state. The active window remains active. 
'9 Restore & Activate. Specify this flag when restoring a minimized window. 
'10 Sets the show-state based on the state of the program that started the application.

VBScript Launch programs whose path contains spaces

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files\Mozilla Firefox\firefox.exe""")
Set objShell = Nothing