0

I am trying Writing a remote desktop client for use in my testing environment.

The goal is to logon to a computer (new virtual machine) for the first time, let the user profile and everything that happens during the first logon happen, and then log off.

I'm able to create the session and logon to the computer as the user using the MSTSCLib/AxMsRdpClient6NotSafeForScripting interfaces.

Now I am wanting to log the user off the computer (not just disconnect) using the WTSLogoffSession function. But this function requires the Session ID and I cannot figure out how to find it for the current session running in the RdpClient interfaces.

Where/how do you find the session id for the session in the RDP session that you have created? It seems like this should be a property or something easily found somewhere but I have found it anywhere.

I assume that I am going to hit myself in the head when a simple solution is given, but it is avoiding me so far.

Thanks

prshaw
  • 41
  • 5

1 Answers1

0

I don't think it's possible to fetch the session ID from the RDP control interfaces (I've tried and would love to be proven wrong!). Your best bet would probably be to find the latest session on the server using WTSEnumerateSessions and WTSQuerySessionInformation (with WTSInfoClass = WTSSessionInfo to fetch the logon time from the WTSINFO structure) or using a wrapper library like Cassia (if you are using a .NET language and don't want to deal with the P/Invokes).

Dan Ports
  • 1,421
  • 9
  • 7
  • I was holding off accepting this because like you I was hoping you would be proven wrong. Looks like we are both disappointed. – prshaw Jun 18 '12 at 16:42
  • Yep... :/ I'm guessing that MS sees the session ID as a server side implementation detail that isn't relevant to the client side. – Dan Ports Jun 18 '12 at 21:08