Knowing when a process has finished
Author |
Message |
Tiago Victor Gehrin #1 / 7
|
 Knowing when a process has finished
Hi, I have a COM Server that opens several files, of different applications, using 'ShellExecute'. I would like to know when one of these called applications has finished, and perform some operations in the modified files. What I have in mind is to store the resulting HINSTANCE value of ShellExecute and, inside the message pump loop of my com object, call some function that would tell me in some way if the process is still running... I don't know witch function to use, and would wish to know if someone has a better idea... Thanks, Tiago Gehring
|
Sat, 09 Aug 2003 05:08:13 GMT |
|
 |
Guillaume Landr #2 / 7
|
 Knowing when a process has finished
Quote: > Hi, > I have a COM Server that opens several files, of different applications, > using 'ShellExecute'. I would like to know when one of these called > applications has finished, and perform some operations in the modified > files. What I have in mind is to store the resulting HINSTANCE value of > ShellExecute and, inside the message pump loop of my com object, call some > function that would tell me in some way if the process is still running... > I don't know witch function to use, and would wish to know if someone has a > better idea...
The last line of ShellExecute's doc is: /*** MSDN QUOTE To obtain information about the application that is launched as a result of calling ShellExecute, use ShellExecuteEx END MSDN QUOTE ***/ With ShellExecuteEx() you have a HANDLE to the new process on which you can wait. Cheers, Guillaume. Quote: > Thanks, > Tiago Gehring
|
Sat, 09 Aug 2003 16:35:16 GMT |
|
 |
David Lownde #3 / 7
|
 Knowing when a process has finished
Quote: >I have a COM Server that opens several files, of different applications, >using 'ShellExecute'. I would like to know when one of these called >applications has finished, and perform some operations in the modified >files. What I have in mind is to store the resulting HINSTANCE value of >ShellExecute and, inside the message pump loop of my com object, call some >function that would tell me in some way if the process is still running...
The HINSTANCE returned by ShellExecute is no use for this - it's merely a code that you can use to determine if the ShellExecute succeeded. If you use ShellExecuteEx you may be able to get a process handle - except if the shell invokes an application like Word and you don't get a separate process invoked! Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq My address is altered to discourage junk mail. Please post responses to the newsgroup thread, there's no need for follow-up email copies.
|
Sat, 09 Aug 2003 16:44:48 GMT |
|
 |
Joe Delekt #4 / 7
|
 Knowing when a process has finished
Greets, Unless, of course, one uses AssocQueryString() with the ASSOCF_OPEN_BYEXENAME flag and then uses CreateProcess() with the resulting executable name in order to get a handle that can be used to wait upon with WaitForSingleObject() and then closed. :) Regards, Joe
Quote: > >I have a COM Server that opens several files, of different applications, > >using 'ShellExecute'. I would like to know when one of these called > >applications has finished, and perform some operations in the modified > >files. What I have in mind is to store the resulting HINSTANCE value of > >ShellExecute and, inside the message pump loop of my com object, call some > >function that would tell me in some way if the process is still running... > The HINSTANCE returned by ShellExecute is no use for this - it's > merely a code that you can use to determine if the ShellExecute > succeeded. > If you use ShellExecuteEx you may be able to get a process handle - > except if the shell invokes an application like Word and you don't get > a separate process invoked! > Dave > -- > MVP VC++ FAQ: http://www.mvps.org/vcfaq > My address is altered to discourage junk mail. > Please post responses to the newsgroup thread, > there's no need for follow-up email copies.
|
Mon, 11 Aug 2003 12:03:51 GMT |
|
 |
David Lownde #5 / 7
|
 Knowing when a process has finished
Quote: > Unless, of course, one uses AssocQueryString() with the >ASSOCF_OPEN_BYEXENAME flag and then uses CreateProcess() with the resulting >executable name in order to get a handle that can be used to wait upon with >WaitForSingleObject() and then closed. :)
JOe, While that would work, it may not give the result that a user would hope for. It would depend on what the application does. For example, a 2'nd instance of a program may start up, communicate with the first instance to have it load the document, then terminate itself. Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq My address is altered to discourage junk mail. Please post responses to the newsgroup thread, there's no need for follow-up email copies.
|
Mon, 11 Aug 2003 15:38:40 GMT |
|
 |
Joe Delekt #6 / 7
|
 Knowing when a process has finished
Greets, That's true. Never looked at it from that perspective; I can certainly see how it might ruin one's day though. :) Regards, Joe
Quote: > > Unless, of course, one uses AssocQueryString() with the > >ASSOCF_OPEN_BYEXENAME flag and then uses CreateProcess() with the resulting > >executable name in order to get a handle that can be used to wait upon with > >WaitForSingleObject() and then closed. :) > JOe, > While that would work, it may not give the result that a user would > hope for. It would depend on what the application does. For example, a > 2'nd instance of a program may start up, communicate with the first > instance to have it load the document, then terminate itself. > Dave > -- > MVP VC++ FAQ: http://www.mvps.org/vcfaq > My address is altered to discourage junk mail. > Please post responses to the newsgroup thread, > there's no need for follow-up email copies.
|
Tue, 12 Aug 2003 01:23:18 GMT |
|
 |
Joe Delekt #7 / 7
|
 Knowing when a process has finished
Greets, Actually, it did make me think of something else. ;) If the application being waited upon was only guaranteed to be run one at a time by the process launching it and sequentially, then perhaps the individual can launch the application in the context of another user. However, this may also have side effects as well. I suppose there are thousands of ways of doing things and not all of them are perfect. :) Regards, Joe
Quote: > > Unless, of course, one uses AssocQueryString() with the > >ASSOCF_OPEN_BYEXENAME flag and then uses CreateProcess() with the resulting > >executable name in order to get a handle that can be used to wait upon with > >WaitForSingleObject() and then closed. :) > JOe, > While that would work, it may not give the result that a user would > hope for. It would depend on what the application does. For example, a > 2'nd instance of a program may start up, communicate with the first > instance to have it load the document, then terminate itself. > Dave > -- > MVP VC++ FAQ: http://www.mvps.org/vcfaq > My address is altered to discourage junk mail. > Please post responses to the newsgroup thread, > there's no need for follow-up email copies.
|
Tue, 12 Aug 2003 01:29:55 GMT |
|
|
|