Kill All Running Process

private void KillProcess(string processName){
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//Get all instances of proc that are open, attempt to close them.
try{
foreach (Process thisproc in Process.GetProcessesByName(processName)) {
if(!thisproc.CloseMainWindow()){
//If closing is not successful or no desktop window handle, then force termination.
thisproc.Kill();
}
} // next proc
}
catch(Exception Exc)
{
msg.Text+= “Attempt to kill ” +procname.Text + ” Failed. “;
}
}

//In the Button_click..add the following

KillProcess(procname.Text);

Explore posts in the same categories: .Net, C#

Comment: