The following class is a process manager, that helps to find and kill process with Id or name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Diagnostics; | |
namespace killercodes_in.ProcKiller | |
{ | |
//Process Killer | |
class IProcKiller | |
{ | |
public void I_KillByName(string ProcName) | |
{ | |
try | |
{ | |
Process[] processByName = Process.GetProcessesByName(ProcName); | |
//Process pogo = Process.GetProcesses(); | |
foreach (Process pr in processByName) | |
{ | |
pr.Kill(); | |
} | |
} | |
catch | |
{ | |
Console.WriteLine("Cannot terminate " + ProcName + "\n"); | |
} | |
} | |
public void I_KillByWinName(string WindowName) | |
{ | |
//bool res; | |
try | |
{ | |
Process[] pro = Process.GetProcesses(); | |
foreach (Process p in pro) | |
{ | |
if (p.MainWindowTitle.Equals(WindowName)) | |
{ | |
p.Kill();; | |
} | |
else | |
{ | |
} | |
} | |
} | |
catch | |
{ | |
System.Windows.Forms.MessageBox.Show("Cannot terminate " + WindowName + "\n Process Not found", "Erraor:"); | |
} | |
//return true; | |
} | |
} | |
} |