|
-
Oct 10th, 2001, 11:59 PM
#1
Thread Starter
PowerPoster
Know When Program's finished or exiting HELP
Hey all,
Does anyone know how i can tell when a program is bieng closed?
Or when it's finsihed doing something?
For example:
I want to be able to tell when Adaptec Cd Writer as finished writing a cd OR is bieng closed and then launch my app.
thanks for any help
Beacon
-
Oct 11th, 2001, 03:28 AM
#2
Junior Member
Check this out
Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long
Declare Function CloseHandle Lib "Kernel32" (ByVal hObject As Long) As Long
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Const WAIT_FAILED = -1&
Public Const WAIT_OBJECT_0 = 0
Public Const WAIT_ABANDONED = &H80&
Public Const WAIT_ABANDONED_0 = &H80&
Public Const WAIT_TIMEOUT = &H102&
Public Const WAIT_IO_COMPLETION = &HC0&
Public Const STILL_ACTIVE = &H103&
Public Const INFINITE = -1&
Function WaitOnProgram(ByVal idProg As Long, _
Optional ByVal WaitDead As Boolean) As Long
Dim cRead As Long, iExit As Long, hProg As Long
Dim iResult As Long
' Get process handle
hProg = OpenProcess(PROCESS_ALL_ACCESS, False, idProg)
If WaitDead Then
' Stop dead until process terminates
iResult = WaitForSingleObject(hProg, INFINITE)
If iResult = WAIT_FAILED Then MsgBox "fail"
' ErrRaise Err.LastDllError ' Get the return value
GetExitCodeProcess hProg, iExit
Else
' Get the return value
GetExitCodeProcess hProg, iExit
' Wait, but allow painting and other processing
Do While iExit = STILL_ACTIVE
DoEvents
GetExitCodeProcess hProg, iExit
Loop
End If
CloseHandle hProg
WaitOnProgram = iExit
End Function
-
Oct 12th, 2001, 01:10 AM
#3
Thread Starter
PowerPoster
Thanks tpiano
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|