How to get the list of Running Applications in C#

This article demonstrates a very simple approach to finding out the list of the applications currently running on a machine.
We use the Process.GetProcesses() method to get the all processes that are currently running on your computer. However, this shows all running processes on the machine so that we’ll need to do is filter out those processes that have an empty MainWindowTitle.
 
List of the running applications
 
A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window then MainWindowTitle property of the process will be empty string (“”).

The following example binds all Running applciations that have a window to the ListBox control named listBox1.

private void Form1_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ProcessName");
            dt.Columns.Add("ProcessId");
            foreach (Process p in Process.GetProcesses("."))
            {
                try
                {
                    if (p.MainWindowTitle.Length > 0)
                    {
                        dt.Rows.Add();
                        dt.Rows[dt.Rows.Count - 1][0] = p.MainWindowTitle;
                        dt.Rows[dt.Rows.Count - 1][1] = p.Id.ToString();
                    }
                }
                catch { }
            }
 
            listBox1.DataSource = dt;
            listBox1.DisplayMember = "ProcessName";
            listBox1.ValueMember = "ProcessId";
}

 
Let’s examine the above program closely, first we create a datatable object and add the columns then check the MainWindowTitle property of the each process in Get.Process() collection. And add the process name and process if to the datatable that has empty MainWindowTitle property.
For getting the process id of the selected running application:
 

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.ValueMember != "")
            {
                textBox1.Text = listBox1.SelectedValue.ToString();
            }
        }