procName 是进程名,不带.exe 。
private bool IsAppKill(String procName) { try { int tryCnt = 0; System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName(procName); while (myProcesses.Length > 0) { try { Application.DoEvents(); myProcesses[0].Kill(); myProcesses[0].WaitForExit(); myProcesses[0].Close(); myProcesses = System.Diagnostics.Process.GetProcessesByName(procName); } catch (Exception ex2) { } tryCnt += 1; if (tryCnt >= 10)//尝试10次后,终止。 { return false; } } } catch (Exception ex) { } return true; }
-