Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Kill() vs Process.Start("taskkill",...)

Tags:

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?

like image 267
Marcus Avatar asked May 31 '11 15:05

Marcus


People also ask

What does process kill do?

The Kill method forces a termination of the process, while CloseMainWindow only requests a termination. When a process with a graphical interface is executing, its message loop is in a wait state. The message loop executes every time a Windows message is sent to the process by the operating system.

How do I kill a task in CMD?

a) Type the following command into the command prompt, to kill only one Process, and press Enter Key. For Example - To kill Notepad, run the command as, taskkill /PID 2404 /F, where /F is used to kill the process forcefully.

How do I use taskkill?

You would first type in the command like your normally would. For example, to forcefully kill notepad.exe, you would type in taskkill /IM notepad.exe . Add /F to the end of the command. The "/F" argument tells taskkill that you want to forcefully end the process.


1 Answers

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

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

like image 188
Ashraf Avatar answered Nov 03 '22 04:11

Ashraf