Get all opened windows in C#

With the following code you can get all opened windows for the current user.

public void GetOpenWindows()
{
    IntPtr hwnd;
    try
    {
    	foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses())
 		if ((hwnd = proc.MainWindowHandle) != IntPtr.Zero)
			Console.WriteLine(hwnd.ToString() + " " + proc.MainWindowTitle);
    }
    catch (Exception)
    {
    }
}
Categories: C# Tags: , , ,
%d bloggers like this: