Link to home
Start Free TrialLog in
Avatar of allanmce
allanmce

asked on

Get the client name for a Terminal Services Session in a program

I am trying to get a reliable client name in a program for a Windows 2003 server terminal services session. (I am using Delphi but the question is really a Terminal Services question rather than a Delphi question). I read the environment variable 'CLIENTNAME' which works well most of the time but I have discovered the following problem.

If users log in on the SAME USER NAME so that there are multiple TS sessions under the same user name then even though they are logging from different computer names the 'CLIENTNAME' variable in all the sessions is set to the same value (the first or last one logged in I assume, I haven't checked in detail).

Is there a way around this so that the correct machine name or client name of the logged in user of the session that is running the program can be derived by the program, even for multiple logins for the same user name?

Any help would be gratefully appreciated.
ASKER CERTIFIED SOLUTION
Avatar of ashleyknowles86
ashleyknowles86
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
correction, that command should be "query session"
Avatar of allanmce
allanmce

ASKER

thanks for your response

I tried logging on terminal services to a win 2000 server and ran quser.exe but it doesn't give the logged in computer name - I also tried 'query session' and it gave similar info but, unfortunately, not the logged in machine name. As you said the 'device' column is empty.

I am hoping to be able to reliably access the logged in machine name for a TS session. The environment variable 'CLIENTNAME' comes close but can be incorrect as mentioned in the original question.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, thanks for replying,
These are handy tools but I couldn't see how to  get the computer name of the current logged in TS user which is what I am after.
With cconnect.exe (the command line version of connect.exe) the web site says that it is included in the installed files, but it isn't, only the desktop version connect.exe is supplied.
http://download.microsoft.com/download/f/d/0/fd05def7-68a1-4f71-8546-25c359cc0842/limitlogin.exe

Looks to be the same.

"Displaying the logins information of any user in the domain according to a specific criterion (e.g. all the logged-on sessions to a specific client machine or Domain Controller, or all the machines a certain user is currently logged on to)."
hmmm...I see what you mean by 'easy?' .. a bit convoluted!
I have looked at limitlogin help and it looks like it could return the required information but I am looking at something I can access by program in some way.. I can capture info by shelling a console program..I will look further into limitlogin and maybe WMI as recommended by the first response above
(if my responses seem slow my time zone is GMT+10 so am probably out of sync with most experts)
Thanks for responding - I split points between the two responders - I am pointed in the right direction