How can I kill Selected process ?

Hello,

this code get a list of runing processes :

Process[] pArry = Process.GetProcesses();

foreach (Process p in pArry)

{

string s = p.ProcessName;

s = s.ToLower();

listBox1.Items.Add(p.ProcessName);

}

so how can I kill the selected processName from listBox1

Best Regards




Answer this question

How can I kill Selected process ?

  • gbereny

    You said in the end that "this is why xp doesn't colapse easly like previous windows".

    Maybe so, you right, but that is the most good thing for a virus, for example if some process is a virus, if know it is a virus and you will probably want to kill that process.

    If you kill the process it will restart again , Right

    The virus itself will inject it self in the protected area of the system, and it is unstoppable.

    Except for Anti-Virus software's.


  • Waldemar Erhardt

    hi,

    Thanks shakalama

    this solved the problem

    Thank you



  • Dan Moorehead

    hi, in addition to what karthic said you can do something like this


    Process[] pArry = Process.GetProcesses();
    private void button1_Click(object sender, EventArgs e)
    {
    foreach (Process p in pArry)
    {
    string s = p.ProcessName;
    s = s.ToLower();
    listBox1.Items.Add(p.ProcessName);
    }
    }
    private void button2_Click(object sender, EventArgs e)
    {
    int indx = listBox1.SelectedIndex;
    Process proc = pArry[indx];
    if (proc.HasExited == false)
    {
    proc.Kill();
    proc.Dispose();
    listBox1.Items.RemoveAt(indx);
    }
    }


    hope this helps



  • Kunal Yadav

     

    hi,
    Thanks Karthik and shakalama for help

    I added listBox1.Items.Clear(); before of ListProcesses button to clear the list,
    But if I ran any application and press the ListProcesses button again then I cannot see the new process in my list

    Second problem, When I kill any running Process and try to click ListProcesses button I get exeptionhi,
    Thanks Karthik and shakalama for help

    I added listBox1.Items.Clear(); before of ListProcesses button to clear the list,
    But if I ran any application and press the ListProcesses button again then I cannot see the new process in my list

    Second problem, When I kill any running Process and try to click ListProcesses button I get exeption and yellow mark on "string s = p.ProcessName;", If we removed that line then the exption will mark on 'listBox1.Items.Add(p.ProcessName);'
    Third Problem, Some applications cannot be killed when I kill many processes(not at same time)


    Thanks



  • Daniel Herling

    hi,

    you have to refill your array something like this

    pArry = Process.GetProcesses();

    there are some process you can't kill if you killed it , it will restart again particulary the system process , this is why xp doesn't collapse easly like previous windows

    hope this helps



  • ptukey

    Try something like-

    Lets say the user clicked a listbox item and you get the name of the process.Lets say it is selectedProcess.

    Process[] pArry = Process.GetProcesses();

    foreach (Process p in pArry)

    {

    string s = p.ProcessName;

    if(s == selectedProcess)

    {

    p.Kill();

    break;

    }

    }

    Or am I missing something


  • zambiniman

    you welcome

  • How can I kill Selected process ?