Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Mon, 11 Aug 2008 08:36:25 -0700,    group: microsoft.public.platformsdk.base        back       


Detecting with CMD.exe is about to terminate   
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?
date: Mon, 11 Aug 2008 08:36:25 -0700   author:   CcB

Re: Detecting with CMD.exe is about to terminate   
"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
date: Mon, 11 Aug 2008 22:53:53 -0400   author:   Gary Chanson

Re: Detecting with CMD.exe is about to terminate   
"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
date: Fri, 29 Aug 2008 14:10:01 -0400   author:   William DePalo [MVP VC++]

Re: Detecting with CMD.exe is about to terminate   
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?
date: Thu, 11 Sep 2008 02:56:50 -0700   author:   Sam Hobbs _change_social_to_socal

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us