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?
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.
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.
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.
p.kill() doesn't kill the process tree.
So taskkill is needed if you want to kill the whole process tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With