1. 程式人生 > >C#殺死Word,Excel等程序

C#殺死Word,Excel等程序

private void KillProcess(string processName)
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//得到所有開啟的程序
    try{
    foreach (Process thisproc in Process.GetProcessesByName(processName)) {
       if(!thisproc.CloseMainWindow()){
	thisproc.Kill();
	}
        }
      }
    catch(Exception Exc)
    {
        msg.Text+= "殺死" + processName + "失敗!";
    }
}