Results 1 to 3 of 3

Thread: Know When Program's finished or exiting HELP

  1. #1

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188

    Unhappy 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

  2. #2
    Junior Member
    Join Date
    Oct 2001
    Posts
    19
    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

  3. #3

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    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
  •  



Click Here to Expand Forum to Full Width