Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting with CMD.exe is about to terminate

1 view
Skip to first unread message

CcB

unread,
Aug 11, 2008, 11:36:25 AM8/11/08
to
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?

Gary Chanson

unread,
Aug 11, 2008, 10:53:53 PM8/11/08
to

"CcB" <C...@discussions.microsoft.com> wrote in message
news:81D84D77-BFAC-4CFC...@microsoft.com...

No.

--

- Gary Chanson (Windows SDK MVP)
- Abolish Public Schools

William DePalo [MVP VC++]

unread,
Aug 29, 2008, 2:10:01 PM8/29/08
to
"CcB" <C...@discussions.microsoft.com> wrote in message
news:81D84D77-BFAC-4CFC...@microsoft.com...

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

Sam Hobbs

unread,
Sep 11, 2008, 5:56:50 AM9/11/08
to
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" <C...@discussions.microsoft.com> wrote in message
news:81D84D77-BFAC-4CFC...@microsoft.com...

0 new messages