Suspend Code While Waiting for Shelled Process

Suspend Code While Waiting for Shelled Process

This “wait” routine suspends your code and waits for the shelled process to finish. It comes in handy when you need to run another scriptatch file during your process. Use this calling syntax:

 Private sub cmdPrint_Click()	WaitForProcessToEnd "C:PLOTTER.BAT"	'Let the user know when the process is finished.	MsgBox "The process is finished! "End Sub

Here are the API declarations:

 Public Const INFINITE = -1&Public Declare Function WaitForSingleObject _	Lib "kernel32" (ByVal hHandle As Long, _	ByVal dwMilliseconds As Long) As LongPublic Declare Function OpenProcess Lib _	"kernel32" (ByVal dwAccess As Long, _	ByVal fInherit As Integer, _	ByVal hObject As Long) As LongPublic Sub WaitForProcessToEnd(cmdLine As String)	'You can substitute a discrete time 	'value in milliseconds for INFINITE.	Dim retVal As Long, pID As Long, pHandle _		As Long	pID = Shell(cmdLine)	pHandle = OpenProcess(&H100000, True, pID)	retVal = WaitForSingleObject(pHandle, INFINITE)End Sub
See also  Monetize TikTok For Your Business

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist