C#杀掉进程的方法
private static string CmdName = "cmd"; /// <summary> /// 关闭进程 /// </summary> /// <param name="processName">进程名</param> private void KillProcess(string processName) { Process[] myproc = Process.GetProcesses(); foreach (Process item in myproc) { if (item.ProcessName == processName) { item.Kill(); } } }
调用方式:
KillProcess(CmdName);