如何杀死多个进程

本文关键字:进程 何杀死 | 更新日期: 2023-09-27 18:14:19

我需要一些帮助,在一个程序我正在创建!我有一个简单的任务管理器,我可以杀死一个进程!然而,我需要它,所以我可以杀死多个进程,被卡住了几天,有点不确定如何杀死多个进程。谁能给我点建议?

通过多进程,我不意味着只是把更多的进程沿着firefox,我的意思是从listview或sql加载多个进程?

是我到目前为止的代码。我在想也许有可能将进程保存为sql,然后将它们加载到狐狸所在的位置?

foreach (System.Diagnostics.Process pr in System.Diagnostics.Process.GetProcesses())//GETS PROCESSES
{
  if (pr.ProcessName == "firefox")//KILLS FIREFOX.....REMOVE FIREFOX.....CONNECT SAVED SQL PROCESSES IN HERE MAYBE??
  {
      pr.Kill(); //KILLS THE PROCESSES
  }
}

如何杀死多个进程

DataSet ds = new DataSet();// SQL STUFF
SqlConnection con = new SqlConnection(ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT ProcessName FROM ApplicationProcesses", con);
// since you start from SqlDataAdapter I'm continue from there..           
da.Fill(ds, "ProcessNames");
// get the process in the database to a array
string[] preocesArray = ds.Tables["ProcessNames"]
        .AsEnumerable()
        .Select(row => row.Field<string>("ProcessName"))
        .ToArray();
// kill the process if it is in the list 
var runningProceses = System.Diagnostics.Process.GetProcesses();
for (int i = 0; i < runningProceses.Length; i++)
{
    if (preocesArray.Contains(runningProceses[i].ProcessName))
    {
        runningProceses[i].Kill(); //KILLS THE PROCESSES
    }
}