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.
Editors IDEsMicrosoft Server OSWindows Server 2003

Avatar of undefined
Last Comment
allanmce

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ashleyknowles86

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ashleyknowles86

correction, that command should be "query session"
ASKER
allanmce

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
Relentim

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
allanmce

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Relentim

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)."
Relentim

ASKER
allanmce

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)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
allanmce

Thanks for responding - I split points between the two responders - I am pointed in the right direction