How can i get the Client Computer name

一个人想着一个人 提交于 2019-12-04 20:31:22
Panagiotis Kanavos

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 TerminalServicesManager().CurrentSession.ClientName

Another SO thread shows how to retrieve the current session's client name or the client names of all sessions.

On the client, use:

string machineName = Environment.MachineName;
string ComputerName1 = Dns.GetHostName();//Server Name
string ComputerName2 = Environment.MachineName;//Server Name  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!