2012-2-7列举及终止进程

1、匹配完整进程名:

System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName("MSACCESS");

            while (ps.Length > 0)          {                 ps[0].Kill();

                 System.Threading.Thread.Sleep(20);

                 ps = System.Diagnostics.Process.GetProcessesByName("MSACCESS");

             }

 

/////////////

2、匹配部分进程名

             string tempName = "";

             int begpos;

             int endpos;

             foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())            

             {

                 tempName = thisProc.ToString();

                 begpos = tempName.IndexOf("(") + 1;

                 endpos = tempName.IndexOf(")");

                 tempName = tempName.Substring(begpos, endpos - begpos);

                if (tempName == "MSACCESS")

                 {

                     thisProc.Kill();//当发送关闭窗口命令无效时强行结束进程

                     while (!thisProc.HasExited) System.Threading.Thread.Sleep(10);

                     System.Threading.Thread.Sleep(100);

                 }

             }

posted on 2016-10-15 18:49  mol1995  阅读(170)  评论(0编辑  收藏  举报

导航