Search code examples
c#terminal-services

Terminal Services command "Query Session" in C#


I'm looking to retrieve this information using C#. I know that I can Shell out and execute these commands, but I'm hoping that I can do it all through System.Diagnostic namespace... enter image description here


Solution

  • Cassia did the trick for me...

    From the link listed above, and thans to Alex K for pointing me in the right direction, I just didn't was to do any p/invoke without a covering library.

    Cassia supports the following operations on both local and remote terminal servers: * Enumerating terminal sessions and reporting session information including connection state, user name, client name, client display details, client-reported IP address, and client build number (WTSEnumerateSessions, WTSQuerySessionInformation, and friends) * Logging off a session (WTSLogoffSession) * Disconnecting a session (WTSDisconnectSession) * Displaying a message box in a session and getting a response from the user (WTSSendMessage) * Enumerating all processes (WTSEnumerateProcesses) * Killing a process (WTSTerminateProcess) * Shutting down or rebooting the server (WTSShutdownSystem) In addition, Cassia supports enumerating all terminal servers on a domain (WTSEnumerateServers).