Remote Desktop Services - Thin Clients Name

I am utilizing Remote Desktop services (Terminal Services) on a Server 2019 VM. I need to be able to get the Client’s name from terminal services as I can’t use Client HostName or IP address as that is the same for all clients as it reports the RDS Server info. I need to differentiate between the clients to auto-login certain default users on certain clients.

I am hoping I can get this info in Python behind the scenes but not sure where to look.

I have done this in another unnamed SCADA package before - but they have built-in script
TseGetClientNodeName( ) - which returns the terminal services client name.

Some quick googling suggests the CLIENTNAME and SESSIONNAME environment variables may have useful values in them.

from java.lang import System

print System.getenv("CLIENTNAME")

If that doesn’t work I’m not sure, maybe someone more familiar with WTS/RDS has a better idea.

Thanks Kevin that worked. - I searched on google for about an hour but was searching the wrong way :slight_smile: I was searching python to get back the TS user name - never dawned on me to try searching Java scripts.

Thanks -

You can do this with python too using os.environ. I just always reach for Java APIs because that’s what I know better.

Ok thanks.

I was trying to use os.environ but was failing - I did finally get that to work as well was missing the [] outside of the variable.

import os
print os.environ[('CLIENTNAME')]