'How would I get all Active Windows for each user session on a Windows terminal server in C#?

I am able to get the active window on a local client pc, but on a terminal server you will have multiple user sessions.

I have used WTSQuerySessionInformation to get the user sessions, but I am not sure how to retrieve the top window for each session.

GetForegroundWindow only works for the session that the app is running in.

I would really appreciate the help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source