I need to write a program (in C#), to run in the client local machine, that will show a list of our windows servers (Sort of the server names in a ListBox) and let the user choose and subsequently connect via RDC. However, the program needs to know if the user is already connected to one of the listed servers, in which case the client will be advised to first disconnect from previous session before continuing. The question is how to detect if there is already such an active connection in the user l开发者_高级运维ocal machine? And better yet, would it be possible to detect the ip address of this server, so that we can ignore the connection if it is not in one of our servers?
You mean like "query session" command-line? I guess you can do it with WMI, look around the Win32_LogonSession class.
The unmanaged API function WTSEnumerateSessions lets you query a remote server for all current sessions. As a starting point for C#, there is of course a P/Invoke signature at pinvoke.net
精彩评论