How can I get the window handle by giving the process name or window title in c#.. given the process is in running already
+6
A:
You can use the Process
class.
Process[] processes = Process.GetProcessesByName("someName");
foreach (Process p in processes)
{
IntPtr windowHandle = p.MainWindowHandle;
// do something with windowHandle
}
Eclipsed4utoo
2009-12-23 15:58:34
+1. Good answer. This will work if it's the main window handle that's needed.
David Stratton
2009-12-23 16:02:26
Note that MainWindowHandle returns 0 if the main window is hidden...
Thomas Levesque
2009-12-24 01:11:26