usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Diagnostics;namespacekillprocess{classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please enter a process name:"); stringProcessName =Console.ReadLine (); intKillvalue =0; Killvalue=Killproc (processName); //Closeprocess.killproc (processName, ref killvalue); Switch(killvalue) { Case 0: Console.WriteLine ("Process {0} closed successfully", ProcessName); Break; Case 1: Console.WriteLine ("There are currently no running processes!"); Break; Case 2: Console.WriteLine ("error ending process {0}! ", ProcessName); Break; default: Break; } console.readkey (); } /// <summary> ///methods to close the specified process/// </summary> /// <param name= "ProcessName" >Process Name</param> /// <returns></returns> Private Static intKillproc (stringprocessName) { intKillvalue =0; Try{process[] PS=process.getprocesses (); if(PS = =NULL) {Killvalue=1; returnKillvalue; } foreach(Process IteminchPS) { if(item. Processname.tolower () = =Processname.tolower ()) {Item. Kill (); } } } Catch //An exception occurred indicating that the kill process failed{Killvalue=2; } returnKillvalue; } }}
07-Console program implementation shutdown process