Home All Groups Group Topic Archive Search About

Need to know when a process is exited

Author
11 Oct 2005 6:59 PM
Ralph Malph
I am writing an app which will use the shell cmd to run a client program on a
mapped drive. This 3rd party program is just a startup program for the actual
application. I need to know when that application has been exited. When the
app start up program ends the shell instance ends which is why I can not use
various methods one would normally use with the shell command to determine
when the program it runs is done. The "final" app starts a process which is
listed as "codefind.exf" (yes .exf not .exe) under the Image Name in task
manager processes. Is there a way to use that name with some sort of API call
to find out when the application exits/the codefind.exf stops?

Any and all help would be greatly appreciated.

Thanks,

Ralph Malph

Author
11 Oct 2005 7:19 PM
Tom Gaughan
Try this...

Private Declare Function OpenProcess Lib "kernel32" _
    (ByVal dwDesiredAccess As Long, _
     ByVal bInheritHandle As Long, _
     ByVal dwProcessId As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
    (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long

Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const PROCESS_TERMINATE = &H1
Private Const STATUS_PENDING = &H103&


Private Function fnlShellProgram() As Long

    Dim lProcessHandle As Long
    Dim lProcessId As Long
    Dim lExitCode As Long

    On Error GoTo ShellProgramError
    lProcessId = Shell("c:\myprogram.exe", 1)

    fnlShellProgram = lProcessId

    If (lProcessId = 0) Then
        ' shell failed
        Exit Function
    End If

    ' Get terminate access
    lProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION Or
PROCESS_TERMINATE, False, lProcessId)

    ' this loop will execute until the process that was launched is
terminated
    Do
        ' looks for terminate message from launched process
        Call GetExitCodeProcess(lProcessHandle, lExitCode)
        DoEvents

        ' As long as lExitCode = STATUS_PENDING the app is still running...
    Loop While lExitCode = STATUS_PENDING

    Call CloseHandle(lProcessHandle)

    Exit Function

ShellProgramError:
    fnlShellProgram = 0

End Function



Show quoteHide quote
"Ralph Malph" <ralph.ma***@happydays.com> wrote in message
news:ADD9C7A3-EE49-4C53-8A0B-C372EA5B43DB@microsoft.com...
> I am writing an app which will use the shell cmd to run a client program
on a
> mapped drive. This 3rd party program is just a startup program for the
actual
> application. I need to know when that application has been exited. When
the
> app start up program ends the shell instance ends which is why I can not
use
> various methods one would normally use with the shell command to determine
> when the program it runs is done. The "final" app starts a process which
is
> listed as "codefind.exf" (yes .exf not .exe) under the Image Name in task
> manager processes. Is there a way to use that name with some sort of API
call
> to find out when the application exits/the codefind.exf stops?
>
> Any and all help would be greatly appreciated.
>
> Thanks,
>
> Ralph Malph
>
Author
11 Oct 2005 7:26 PM
Ralph
Show quote Hide quote
"Ralph Malph" <ralph.ma***@happydays.com> wrote in message
news:ADD9C7A3-EE49-4C53-8A0B-C372EA5B43DB@microsoft.com...
> I am writing an app which will use the shell cmd to run a client program
on a
> mapped drive. This 3rd party program is just a startup program for the
actual
> application. I need to know when that application has been exited. When
the
> app start up program ends the shell instance ends which is why I can not
use
> various methods one would normally use with the shell command to determine
> when the program it runs is done. The "final" app starts a process which
is
> listed as "codefind.exf" (yes .exf not .exe) under the Image Name in task
> manager processes. Is there a way to use that name with some sort of API
call
> to find out when the application exits/the codefind.exf stops?
>
> Any and all help would be greatly appreciated.
>
> Thanks,
>
> Ralph Malph
>

Are you sure you can't use 'createprocess and wait' or 'shell and wait'?
(Google for those subjects 'VB "shell and wait" sample code')
Does the process create any 'finished' product you could catch with
FindFirstChangeNotification()?

hth
-ralph
Author
11 Oct 2005 8:42 PM
Someone
Use this sample to get ProcessID by executable file name. Then use
OpenProcess() to get a handle to the process.

How To List Running Processes
http://support.microsoft.com/default.aspx?scid=kb;en-us;187913

How To Use a 32-Bit Application to Determine When a Shelled Process Ends
http://support.microsoft.com/default.aspx?scid=kb;en-us;129796


Show quoteHide quote
"Ralph" <nt_consultin***@yahoo.com> wrote in message
news:FK-dnTi-n4EyjNHeRVn-rA@arkansas.net...
>
> "Ralph Malph" <ralph.ma***@happydays.com> wrote in message
> news:ADD9C7A3-EE49-4C53-8A0B-C372EA5B43DB@microsoft.com...
>> I am writing an app which will use the shell cmd to run a client program
> on a
>> mapped drive. This 3rd party program is just a startup program for the
> actual
>> application. I need to know when that application has been exited. When
> the
>> app start up program ends the shell instance ends which is why I can not
> use
>> various methods one would normally use with the shell command to
>> determine
>> when the program it runs is done. The "final" app starts a process which
> is
>> listed as "codefind.exf" (yes .exf not .exe) under the Image Name in task
>> manager processes. Is there a way to use that name with some sort of API
> call
>> to find out when the application exits/the codefind.exf stops?
>>
>> Any and all help would be greatly appreciated.
>>
>> Thanks,
>>
>> Ralph Malph
>>
>
> Are you sure you can't use 'createprocess and wait' or 'shell and wait'?
> (Google for those subjects 'VB "shell and wait" sample code')
> Does the process create any 'finished' product you could catch with
> FindFirstChangeNotification()?
>
> hth
> -ralph
>
>