How can i get the Client Computer name
Solution 1
Assuming you are using Terminal Services and Remote Desktop, you can check the CLIENTNAME environment variable to retrieve the client machine's name, although some people report problems with it.
You can get the value with Environment.GetEnvironmentVariable, eg
var clientName=Environment.GetEnvironmentVariable("CLIENTNAME");
For an API based method, check Preferred way Of getting Client name From Terminal Server Session which shows how to use WMI or the Terminal Services API to retrieve the client name
UPDATE
Hmm, seems the Cassia library encapsulates the TS API. You can get the client name with
new TerminalServicesManager().CurrentSession.ClientName
Another SO thread shows how to retrieve the current session's client name or the client names of all sessions.
Solution 2
On the client, use:
string machineName = Environment.MachineName;
user609511
Updated on July 09, 2022Comments
-
user609511 almost 2 years
I am using C# Framework 4.0 Windows Form. My program is installed on a server TSE. There are 11 light clients that connect to this server.
When one of these clients launches my progam, how can I get his PC name ?
-
JleruOHeP over 11 yearstake a look here: stackoverflow.com/a/1768219/1300049
-
eestein over 11 yearsIs this what you're refering to? stackoverflow.com/questions/804700/…
-
Panagiotis Kanavos over 11 yearsAre you asking how to get the TERMINAL's name while running your application inside your SERVER? What terminal technology are you using? This isn't what client-server means by the way
-
user609511 over 11 yearsYES, terminal name. this terminal is a light PC, they don't have a CD driver nor hardisk. it just a small box that connect to server TSE. They even not have an Operating System installed
-
-
nflash almost 9 yearsThis does not answer the question as the question asks for the client name and not the server (RD Host)
-
Rohit Vyas almost 9 yearsThen What would be the answer? @nflash ??
-
Panagiotis Kanavos almost 8 years@Jerther in some cases
CLIENTNAME
returnsConsole
as described in this Microsoft KB article. I don't remember what else I had found 4 years ago. By now of course Windows XP is no longer supported -
Panagiotis Kanavos almost 8 years@Jerther also found this KB article about RDP connections which applies to Windows 7 and 2008 R2.
-
André Pletschette almost 2 yearsit's about the Citrix Clientname, not the username