I have a small C++ program that starts cmd.exe using CreateProcess. I am trying to detect when the cmd.exe process is about to exit so that I can close all other processes (if any) that have been created by the cmd.exe process. I cannot do this by listening to the message queue as console apps do not have a message queue. Is there another way of doing this?
"CcB" wrote in message news:81D84D77-BFAC-4CFC-A9C4-2FB2AB437254@microsoft.com... >I have a small C++ program that starts cmd.exe using CreateProcess. I am > trying to detect when the cmd.exe process is about to exit so that I can > close all other processes (if any) that have been created by the cmd.exe > process. > I cannot do this by listening to the message queue as console apps do not > have a message queue. > > Is there another way of doing this? No. -- - Gary Chanson (Windows SDK MVP) - Abolish Public Schools
"CcB" wrote in message news:81D84D77-BFAC-4CFC-A9C4-2FB2AB437254@microsoft.com... > I have a small C++ program that starts cmd.exe using CreateProcess. I am > trying to detect when the cmd.exe process is about to exit so that I can > close all other processes (if any) that have been created by the cmd.exe > process. > I cannot do this by listening to the message queue as console apps do not > have a message queue. > > Is there another way of doing this? Maybe. I haven't tried it but I _think_ that your success in that depends on how cmd.exe creates processes. Look up Job Objects: http://msdn.microsoft.com/en-us/library/ms684161(VS.85).aspx Create a job, add the process that runs the image cmd.exe to it. Wait on the cmd.exe process. When it terminates call TerminateJobObject(). As I said, I _think_ that will kill processes that cmd.exe starts with CreateProcess() and without specifying the "break away" flag. Don't forget to close all the handles that you open when you are done. If you go that route, let us know how you do. Regards, Will www.ivrforbeginners.com
I do not understand how a message queue would help if you need the parent to detect the exit of the child, unless you were to do something such as hooks. A console application can however have a message queue; it's creation is determined by the same criteria as for a GUI application. A message queue would be required for a window in a console application. If it is possible to have the exit detection in the console application, then a Signals Handler will be easy and effective. http://simplesamples.info/Windows/SignalsHandler.php "CcB" wrote in message news:81D84D77-BFAC-4CFC-A9C4-2FB2AB437254@microsoft.com... >I have a small C++ program that starts cmd.exe using CreateProcess. I am > trying to detect when the cmd.exe process is about to exit so that I can > close all other processes (if any) that have been created by the cmd.exe > process. > I cannot do this by listening to the message queue as console apps do not > have a message queue. > > Is there another way of doing this?