get processes ID and Kill

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.
 
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.


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);
}
 
D

Duggi

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top