如果不是应用程序打开的进程不能杀掉。那位能帮忙解决??
先释放资源
再dispose
Process[] process = Process.GetProcesses();
foreach (Process prc in process)
{
Console.WriteLine(prc.ProcessName);
if (prc.ProcessName == "Excel")
prc.Kill();
}
Console.ReadLine();
private void KillProcess(string processName)
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
foreach (Process thisproc in Process.GetProcessesByName(processName)) {
if(!thisproc.CloseMainWindow()){
thisproc.Kill();
GC.Collect();
}
Process[] prcs = Process.GetProcesses();
foreach (Process p in prcs) {
if (p.ProcessName.Equals("程序名")) {
p.Kill();
}
}
private void MainFrm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确定退出吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)