Process.Start() and Childs Process

  • Thread starter Thread starter Hakùna kù
  • Start date Start date
H

Hakùna kù

Hello Everybody ,
I have a Process.Start() method that launch a "main.exe" files .

The "main.exe" launch 3 sub-file :
a.exe
b.exe
c.exe

What I want is the When I close the Main.exe , then the sub-file exe must
Close !

Basically is the same as "terminate childs processes..." of TaskManager :
it close All processes generated by a "process" .

Any help ?

Hakùna kù
 
Windows does not know "child processes" as unix has: it only stores the PID
of the process that launched it for each process. So, the task manager
essentially loops through all processes, and builds a graph to terminate the
"child processes". You can do the same, but there is no switch or so that
would do that for you.
You'll need to PInvoke "CreateToolhelp32Snapshot" and "Process32First" for
that.
It's probably a lot easier to:
- store all the process objects in a list in the main exe, and kill them on
shutdown
- use app-domains instead of separate processes
- use background threads instead of processes

Niki
 
I have found a solution that work fine for me .

It use a WMI script and use a Win32_Process to work .

I get all Processes in my Operating System with WMI Query :
"SELECT * from Win32_Process"

so I find all instances with the "ParentProcessId" == at id of your father !

So I know all childs of my Main Process !
And I'll terminated with myProcessChild.Kill();

Hakù
 
Back
Top