c# 关闭进程

来源:互联网 发布:static java 编辑:程序博客网 时间:2024/04/30 22:54
//关闭进程
public void KillProcess(string processName)
{
    System.Diagnostics.Process myproc = new System.Diagnostics.Process();
    //得到所有打开的进程 
    try
    {
        foreach (Process thisproc in Process.GetProcessesByName(processName))
        {
            if (!thisproc.CloseMainWindow())
            {
                if (thisproc != null)
                    thisproc.Kill();
            }
        }
    }
    catch (Exception Exc)
    {
        throw Exc;
        // msg.Text+=  "杀死"  +  processName  +  "失败!"; 
    }
}