title: Get a windows title by it's process name without main window
body: <p>I have a problem I'm trying to get a window's title by it's process name and I can't do it here s what I tried :</p>
  
  <pre><code>Process[] p = Process.GetProcessesByName("Acrobat");
  Console.WriteLine(p[0].MainWindowTitle);
  Console.ReadLine();
  </code></pre>
  
  <p>But the problem is that I can only get it only if the associated process does have a main window. How can I make it working ?</p>
  
  <p>The main goal is that I've a method named BringToFront()
  But this method ask for a caption name which is "thenameofthePDF.pdf - Adobe Acrobat Pro (Yes, acrobat is running with an opened pdf)
  I would like to bring to front my Acrobat window..
  but for this I need the name of the windows as my method is asking for the caption.
   Here is the entire code at the moment:</p>
  
  <pre><code>class Program
  {
      [DllImport("User32.dll")]
      public static extern Int32 SetForegroundWindow(int hWnd);
  
      [DllImport("user32.dll")]
      public static extern int FindWindow(string lpClassName, string lpWindowName);
  
      private static void BringToFront(string className, string CaptionName)
      {
          SetForegroundWindow(FindWindow(className, CaptionName));
      }
  
      static void Main(string[] args)
      {
          // BringToFront("Acrobat", "mypdf.pdf - Adobe Acrobate Pro");
          Process[] p = Process.GetProcesses();
          foreach (var process in p)
          {
             Console.WriteLine(process.MainWindowTitle);
          }
          Console.ReadLine();
      }
  }
  </code></pre>