Silver Light and Blue Sky

C# and Infrastructure. Code is everything.

Getting session source information at RDP session by C#

I'd like to get the information of remote session source at the destination server with this function*1.

WTSQuerySessionInformation function (Windows)

It can be written by C# with DllImport. The value of WTS_CURRENT_SESSION is uint.MaxValue.

gist.github.com

It takes some doing because the structure of ppBuffer is changed depending on the specified value in WTSInfoClass. Here is a struct when WTSInfoClassis WTSClientAddress.

WTS_CLIENT_ADDRESS structure (Windows)

If you get all the sessions except itself, you can use this function.

WTSEnumerateSessions function (Windows)

*1:It seems OK for launching app with UAC elevation