Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi everyone,

To cut the long story short, i am implementing an application that runs another application during a click of a button using Diagnostics.Process.Start() function and also monitor the process of that application. Now my problem is this, i want to know how i can associate the process of the application i started usint Diagnostics.Process.Start() with the process of my .NET application so what whenever my .NET application closes, the process of the application i ran will also close.

I don't want to handle this in the Form1.FormClosing Event. The reason for this is because there might be some malcious users that might go straight into the taskbar manager and terminate the process of my .NET application and leaving the process of the application i ran active thereby removing the monitoring i coded inside my .NET application.

Pls i need help on this, i want to know how i can associate the process of my .NET application and the third party application i ran using Diagnostics.Process.Start() so that whenever my .NET application shuts down, the third party application will also shut down.

Thanks in advance!
Posted

It look that there is a solution to your request. Look here: http://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed#answer-4657392[^]. The code is built around the Job Object tool[^]:
Quote:
A job object allows groups of processes to be managed as a unit. Job objects are namable, securable, sharable objects that control attributes of the processes associated with them. Operations performed on a job object affect all processes associated with the job object. Examples include enforcing limits such as working set size and process priority or terminating all processes associated with a job.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Aug-13 17:30pm    
Oh, I didn't know about that feature. Of course, 5ed.
—SA
Joeadeoye 25-Aug-13 20:21pm    
Hahahaha. Thank You very much. I read through your link carefully and i saw some people commented that the solution ain't working for a 64bit machine which is currently my development computer. So i followed the link provided there and managed to convert the code to vb.net and believe me. IT WORKED PERFECTLY!!! It did the exact thing i want it to do!

Thanks once again. I owe you one hamburger..........lolz...
[EDIT]There is no such thing as association between processes. Processes can be indirectly associated using the job objects, please see Solution 2. At the same time, you can take care about your child processes by yourself. [END EDIT]

First of all, note that Process.Start returns you the instance of the external process started. You can use this instance to kill the process: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx[^].

To do the opposite, to trigger something when the external process is exited, you can use Process.WaitForExit methods:
http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx[^],
http://msdn.microsoft.com/en-us/library/ty0d8k56.aspx[^].

As this call is blocking, in most cases, a separate thread is required to wait.

—SA
 
Share this answer
 
v2
Comments
Zoltán Zörgő 25-Aug-13 16:59pm    
I thought the same, but it looks that there is such thing as association between processes. Look what I have found.

I credited your solutions and fixed my statement.

Thank you very much.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900