How do I get the handle of a console application's window

Grant picture Grant · Aug 14, 2009 · Viewed 50.2k times · Source

Can someone tell me how to get the handle of a Windows console application in C#? In a Windows Forms application, I would normally try this.Handle.

Answer

Thomas Levesque picture Thomas Levesque · Aug 14, 2009

Not sure it works, but you can try that :

IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;