get processes ID and Kill

  • Thread starter Thread starter alexia.bee
  • Start date Start date
A

alexia.bee

Hi All,

I need to get all the IDs of specific process and kill all the
instances of that process.

Something like:

// theArray get all the Excel proc IDs in the Task manager
string[] theArray = new string[100];

//there can be more then one instance of excel in Task manager
theArray = GetAllProcessID("Excel");


for (int i = 1; i 100; i++)
killProcessbyID(theArray);

Thanks for the help.
 
Hi All,

I need to get all the IDs of specific process and kill all the
instances of that process.

Something like:

// theArray get all the Excel proc IDs in the Task manager
string[] theArray = new string[100];

//there can be more then one instance of excel in Task manager
theArray = GetAllProcessID("Excel");


for (int i = 1; i 100; i++)
killProcessbyID(theArray);

Thanks for the help.


NM,
Just found the solution. atleast I learned something. Always google
before you post a new post :(.

Comments are wellcome.

private void button1_Click(object sender, System.EventArgs e)
{
string a = "";
Process[] procList = Process.GetProcesses();
for ( int i=0; i<procList.Length; i++)
{
if(procList.ProcessName.ToString() == "EXCEL")
{
a+= "Process ID="+procList.Id +"\t"+"Process
Name="+procList.ProcessName+"\n";
procList.Kill();
}
}
MessageBox.Show(a);
}
 
Hi

Replacing for loop with for each would look good. Does not effect any
functionality.

string a = "";
Process[] procList = Process.GetProcesses();

foreach (Process p in procList)
{
if (p.ProcessName.ToString() == "EXCEL")
{
a += "Process ID=" + p.Id + "\t" + "Process Name=" +
p.ProcessName + "\n";
p.Kill();
}
}

MessageBox.Show(a);

should work fine and looks readable.

Thanks
-Srinivas.
 
Back
Top