Home » General Scripting and Coding » VBScript » Wait for a Process to Complete

Wait for a Process to Complete

Posted on by

Description:

Useful when we want to wait for a process to complete until we continue execution of a script.

Source:

NA

Script:

This script waits until notepad.exe and iexplore.exe are no longer running:

dim svc : set svc=getobject("winmgmts:root\cimv2")
dim sQuery : sQuery="select * from win32_process where name='notepad.exe' OR name='iexplore.exe'"

Do
dim cproc : set cproc=svc.execquery(sQuery)
If cproc.count = 0 Then
	Exit Do
End If
WScript.Sleep 1000
Loop

 

Comments have now been disabled. If you have a question to ask about this post please ask the community!