Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Sep 17, 1998



How to Help Your Business Become an AI Early Adopter

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 script\batch 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 Long
Public Declare Function OpenProcess Lib _
	"kernel32" (ByVal dwAccess As Long, _
	ByVal fInherit As Integer, _
	ByVal hObject As Long) As Long
Public 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
Charles Douglas
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date