0

I am trying to get all the window handles of applications that have a taskbar icon only.

The solutions I have converted to C# that have failed:

Enumerate windows like alt-tab does

Enumerate windows like alt-tab does

Enumerate windows like alt-tab does

And a couple that I lost track of already. All these solutions either crash or bring up windowless processes like svchost, plugin processes, etc.

Basically I just need the windows that are actively available in the task bar with icons. I am using the window handle of

Process.MainWindowHandle

What are some working solutions to this? Is there a thread with a working solution that I missed?

Community
  • 1
  • 1
Drake
  • 3,851
  • 8
  • 39
  • 48

1 Answers1

1

Try retrieving all processes where the MainWindowTitle property is set.

It doesn't feel like a particularly elegant solution, but it worked for me, bringing back only those applications which were running and visibly open in the taskbar.

List<Process> taskBarProcesses = Process.GetProcesses().
                                         Where(p => !string.IsNullOrEmpty(p.MainWindowTitle))
                                         .ToList();
jdavies
  • 12,784
  • 3
  • 33
  • 33
  • Doesnt work for the window explorer, any way to include those as well? – Drake Oct 14 '11 at 23:46
  • Checkout the following blog post: [Access Explorer and Internet Explorer in C# to Find Web Pages and Directories](http://omegacoder.com/?p=63). It shows how to use the [ShellWindows](http://msdn.microsoft.com/en-us/library/windows/desktop/bb773974(v=vs.85).aspx) object to retrieve a collection of open explorer windows. – jdavies Oct 16 '11 at 20:20