/// <summary>
/// Kill a process, and all of its children.
/// </summary>
/// <param name="pid">Process ID.</param>
private static void KillProcessAndChildren(int pid)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
KillProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
}
try
{
Process proc = Process.GetProcessById(pid);
proc.Kill();
}
catch (ArgumentException)
{
// Process already exited.
}
}
Here is where I collect snippets and interesting article useful to my job. One of these days I should rewrite it in a more organized way. Duccio Fabbri
venerdì 8 marzo 2013
Kill process tree programatically in C#
http://stackoverflow.com/questions/5901679/kill-process-tree-programatically-in-c-sharp
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento