|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Need to know when a process is exitedI 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 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 >
Show quote
Hide quote
"Ralph Malph" <ralph.ma***@happydays.com> wrote in message Are you sure you can't use 'createprocess and wait' or 'shell and wait'?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 > (Google for those subjects 'VB "shell and wait" sample code') Does the process create any 'finished' product you could catch with FindFirstChangeNotification()? hth -ralph 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 > >
Command Button Sequence
Avoid Overflow! 3 dimenional control array Converting decimal to BCD (binary coded decimal)... populating combobox Getting information on a Word document Raised To The Power Of! form_load parameters - novice Expot datas in to excel sheet Best way to have a subroutine modify more than one variable |
|||||||||||||||||||||||