1: /// <summary>
2: /// Kills a process
3: /// </summary>
4: /// <param name="ProcessName">Name of the process without the ending (ie iexplore instead of iexplore.exe)</param>
5: public static void KillProcess(string ProcessName)
6: {
7: Process[] Processes = Process.GetProcessesByName(ProcessName);
8: foreach (Process CurrentProcess in Processes)
9: {
10: CurrentProcess.Kill();
11: }
12: }
13:
14: /// <summary>
15: /// Kills a process after a specified amount of time
16: /// </summary>
17: /// <param name="ProcessName">Name of the process</param>
18: /// <param name="TimeToKill">Amount of time (in ms) until the process is killed.</param>
19: public static void KillProcess(string ProcessName, int TimeToKill)
20: {
21: ThreadPool.QueueUserWorkItem(delegate { KillProcessAsync(ProcessName, TimeToKill); });
22: }
23:
24: /// <summary>
25: /// Kills a process asyncronously
26: /// </summary>
27: /// <param name="ProcessName">Name of the process to kill</param>
28: /// <param name="TimeToKill">Amount of time until the process is killed</param>
29: private static void KillProcessAsync(string ProcessName, int TimeToKill)
30: {
31: if (TimeToKill > 0)
32: Thread.Sleep(TimeToKill);
33: Process[] Processes = Process.GetProcessesByName(ProcessName);
34: foreach (Process CurrentProcess in Processes)
35: {
36: CurrentProcess.Kill();
37: }
38:
39: }