How to get running applications in windows?

.net, c#, cmd, process, windows

Solution

This may help:

Process[] processes = Process.GetProcesses();
foreach(Process p in processes)
{
    if(!String.IsNullOrEmpty(p.MainWindowTitle))
    {
        listBox1.Items.Add(p.MainWindowTitle);
    }
}

Problem

How can I get the list of currently running applications or foreground processes in Windows? I mean the applications that have a window for real. Not the background services/processes. I want to access the same list a task manager shows when we open it. Is there a way? Any type of solution is acceptable. Either a command or a .NET code or anything. I just want to get that list programmatically. Is that even possible? I tired tasklist but it gives me all the services and processes, even the background ones. Is there any logic I could implement?

Original source

Related problems