26

I've a small C# installer application and I want to kill a process. Are there any advantages / differences in using

Process[] procs = Process.GetProcessesByName("[taskname]");
foreach (Process p in procs) { p.Kill(); }

vs

Process.Start("taskkill", "/F /IM [taskname].exe");

I read somewhere that using "taskkill" is only available in XP(and up), so would that make Process.Kill() the safer option?

Marcus
  • 5,407
  • 3
  • 31
  • 54

2 Answers2

27

p.kill() doesn't kill the process tree.

So taskkill is needed if you want to kill the whole process tree.

Ashraf
  • 428
  • 1
  • 5
  • 6
8

Process.Kill is prefered, because you are not starting another process as you do, when you start taskkill to kill the process. It is just a lot of useless overhead.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443