Showing posts with label Wait Until Process Completed. Show all posts
Showing posts with label Wait Until Process Completed. 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.

Friday, February 3, 2017

VBScript - How to make program wait until process has finished

const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
set WScript_Shell = WScript.CreateObject("WScript.Shell")
command1 = "C:\xampp\apache_stop.bat"
command2 = "C:\xampp\apache_start.bat"
Wscript.Echo "Apache Server Stopping"
WScript_Shell.Run command1, DontShowWindow, WaitUntilFinished
Wscript.Echo "Apache Server Stopped"
Wscript.Echo "Apache Server Starting"
WScript_Shell.Run command2, DontShowWindow, DontWaitUntilFinished
Wscript.Echo "Apache Server Started"