views:

20

answers:

0

I am developing a custom version of a gina.dll for Windows XP, it has to behave differently when someone attempts to log on via RDP.

The problem is in figuring out whether I am inside an RDP session or not.

After researching this matter and reviewing various discussions, I established that the following approaches do not work:

  • Check the environment variables: SESSIONNAME and CLIENTNAME are 2 environment variables that are created when the current session is a remote one. This method is not suitable, because these vars are created only after the user has logged on. If you try to check their values before authentication, the system behaves as if they were not set (i.e. you're not in a remote desktop session);
  • GetSystemMetrics has 2 flags that sound attractive: SM_REMOTESESSION and SM_REMOTECONTROL. Unfortunately this method doesn't apply to this case either; it works as expected after I log on, but calling this function while Gina is on the screen returns 0 (as if I weren't in an RDP session);
  • WTSQuerySessionInformation is a function from the Terminal Services API, I was hoping it would do what I want. There are many flags to tinker with, I use WTSConnectState. The problem is that it returns the same values for "local session" and "gina loaded via RDP" - so I cannot rely on it to distinguish a remote desktop session from a local one. There are other flags that sound relevant, ex: WTSClientProtocolType and WTSClientName; but as in the previous case - they cannot distinguish between a "local session" and "gina loaded via RDP".

When I got desperate I just tried all the flags and observed the behaviour of the function, which allowed me to come up with a workaround:

  • verify if WTSUserName is defined
  • if it is not, it means that I am not logged on; i.e. I'm looking at the authentication screen
  • if it is defined and WTSWinStationName is "Console", I am inside a local session
  • if it is defined and WTSWinStationName is not "Console", I am in a remote desktop session

This method works, but I am not comfortable with it because it relies on some indirect clues to come up with an answer. Can someone suggest a better approach?