get window title from pid

MoShe picture MoShe · Apr 3, 2012 · Viewed 7.5k times · Source

I am looking for a way to get the window title from process id.

I would like to build function the get the pid of specific window and return its window title.

I try to use AutoIt but it didn't work.

Any Idea?

Answer

Øyvind Bråthen picture Øyvind Bråthen · Apr 3, 2012

This should be quite simple:

Process.GetProcessById(processId).MainWindowTitle;

And if you like it as a function as you requested:

public string GetWindowTitle(int processId){
  return Process.GetProcessById(processId).MainWindowTitle;
}