Click here to Skip to main content
15,742,150 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help from the Terminal Services/RDP experts here...

Is there a way in C# to get the active (foreground) window on the client side in a TS/RDP environment? (My application is served to the client with their other apps.)

In a local forms app, I can use GetForegroundWindow, GetWindowThreadProcessId, and Process.GetProcessById to get a Process object that is the window in focus.

I understand that I can use Process.SessionId and WTSEnumerateProcesses to file through the running processes in a TS session, but is there a way to determine which process' window is currently active? I did not see an indication of this in the WTS_PROCESS_INFO struct, for example.

Any help you can provide would be awesome!

1 solution

Your app can tell if it's running in a RDP sesssion:

bool isRemote = System.Windows.Forms.SystemInformation.TerminalServerSession;

However, getting any info from the client side seems like it would be a security breach to me.
Share this answer
EngrDave 10-Aug-11 13:22pm    
Thanks, John. My app will always be running in a RDP session. In response to certain events, my app needs to determine whether the user is using (for example) Notepad, or Word at the moment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900