Friday, August 5, 2016

Get Active Process Running in System using C#

Hi in this blog I am going to show how to get the list of active process running in the system using System.Diagnostics namespace in c#.Create a new window application and name it as "GetActiveProcessList" and design a form as show in the fig.




Now write the below code in the button handlers.


private void button1_Click(object sender, EventArgs e)
        {
            processlist();
        }

        private void processlist()


        {
            Process[] processlist = Process.GetProcesses();
            foreach (Process theprocess in processlist)
            {
                string temp = "Process ID:" + theprocess.Id + "\tProcess Name:" + theprocess.ProcessName;
                listBox1.Items.Add(temp);
            }
        }
                
        private void button2_Click(object sender, EventArgs e)
        {           
            listBox1.Items.Clear();
            processlist();
        }

        private void btnKill_Click(object sender, EventArgs e)

        {
            Process p = new Process();
            //Convert.ToInt32(txtProcessID.Text)
            p = Process.GetProcessById(Convert.ToInt32(txtProcessID.Text));
            p.Kill();

        }

processlist() : This function get the list of running in the system and add it to the listitem box.


output:

Download the source code from here.

Click here for my previous blog.



No comments:

Post a Comment