Killing Process Using C#

Killing Process Using C#

Added by Sixth Sense updated on Tuesday, February 6, 2018

Problem:

Here we will discuss different ways to kill a process using c-sharp programmatically.

By Name:

We will search and kill process by name. In this example we will search for nodepad.exe

foreach(Process p in Process.GetProcessesByName("notepad"))
{
	p.Kill();
}				
				

CloseMainWindow:

Closes a process that has a user interface by sending a close message to its main window.

foreach(Process p in Process.GetProcessesByName("notepad"))
{
	p.CloseMainWindow();
}
				

You can call Kill and CloseMainWindow only for processes that are running on the local computer. You cannot cause processes on remote computers to exit. You can only view information for processes running on remote computers.

Earn Money By Signup

  

About

25 Tutorials
19 Snippets
6 Products

More

Contact Us

Contact us

Stay Connected