0

In C# I am trying to get names of all opened windows, so I check processes and display their names.

I have a problem because child processes are not included, how can I include to also child processes not only one?

This is used now:

Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
    if (!String.IsNullOrEmpty(p.MainWindowTitle))
    {
       MessageBox.Show(p.MainWindowTitle);
    }
}
  • 2
    Initially you talk about "child processes" and later you talk about "child windows". Do you want both of these? – Uwe Keim Feb 08 '19 at 12:17
  • Only child window I guess, under process list in task manager those sub-windows are displayed under main process. Now when I use this code only name of last opened sub-window is displayed, not all (or main window name). – SilverSilencer Feb 08 '19 at 12:20
  • 3
    In Task Manager, the sub-elements are sub-processes, not sub-windows. – Uwe Keim Feb 08 '19 at 12:22
  • Possible duplicate of [How can I list all processes running in Windows?](https://stackoverflow.com/questions/648410/how-can-i-list-all-processes-running-in-windows) – Cizzl Feb 08 '19 at 12:25
  • Well I open new forms in C# app thats how they are opened. In another app I need to check all of their titles. – SilverSilencer Feb 08 '19 at 12:41
  • Given a process, obtained the handle of its main window then you can list all children with https://stackoverflow.com/q/1363167/1207195. Also note that, in theory, a process might have many multiple _main_ windows but then things will quickly start to be much more complicate. – Adriano Repetti Feb 08 '19 at 13:46
  • The problem is that every time I open new form in first app, process gets new id (from last opened child, not main), so I can't get ID of main app and than check for it's childs. – SilverSilencer Feb 08 '19 at 16:46
  • Found the solution at https://stackoverflow.com/questions/7268302/get-the-titles-of-all-open-windows – SilverSilencer Feb 08 '19 at 19:55

0 Answers0