I have lets say two processes: notepad and taskmgr open. I want to kill those two or few more processes how can i do this?
So far i came up with this by googling around:
Process.GetProcesses().Where(p => p.ProcessName == "notepad,taskmgr").ToList().ForEach(y => y.Kill());
not sure how to differentiate between two processes above?
That linq query looks to be only finding a process when its name is “notepad,taskmgr”. To get both, use a query like this:
If you’re going to be adding more processes, you might want to do something like this:
You can then add other processes to that list. As for figuring out what ones you’ve found, in your ForEach, you can access the name by
y.ProcessNameand use it in a conditional, where needed.Edit: add
.exeto those process names if needed.