Wednesday, October 20, 2010

C# Tutorial: Simple Task Manager [Kill a Process]

Here is the code

using System.Diagnostics; 
//////////////////////////////////////////////
Process[] procs;
private void GetProcesses()
{
    procs = Process.GetProcesses();
    if (Convert.ToInt32(label2.Text) != procs.Length) // Check if new processes have been started or terminated
    {
        listBox1.Items.Clear(); 
        for (int i = 0; i < procs.Length; i++)
        {
            listBox1.Items.Add(procs[i].ProcessName);  // Add the process name to the listbox
        }
        label2.Text = procs.Length.ToString();  
    }
}
private void Form1_Load(object sender, EventArgs e)
{
    GetProcesses(); 
}

// Check every 1 second for changes in the processes list
private void timer1_Tick(object sender, EventArgs e)
{
    GetProcesses(); 
}

private void button1_Click(object sender, EventArgs e)
{
    procs[listBox1.SelectedIndex].Kill(); // Kill the process coresponding to the selected index of listbox1 
}

private void kIllProcessToolStripMenuItem_Click(object sender, EventArgs e)
{
    procs[listBox1.SelectedIndex].Kill();
}

Or download the solution

3 comments:

  1. If you can, post a topic with something like
    Rat, Stealer, Crypter but if u dont like hacking
    post somethink very good and intresting, i have seen all of your videos in C#, very nice and thanks! :D

    ReplyDelete
  2. @Mega Bet:
    Seriously?

    --> Tutorial:
    Very nice tutorial. I like that smooth music in the background :).

    ReplyDelete