如何在。net c#中获取计算机名


当前回答

System.Environment.MachineName

其他回答

System.Environment.MachineName

或者,如果你使用Winforms,你可以使用System.Windows.Forms.SystemInformation。ComputerName,返回与System.Environment.MachineName完全相同的值。

您可以使用Environment.MachineName访问机器名。

用这一行简化一下

Environment.MachineName;
System.Environment.MachineName

下面给出了获取机器名或计算机名的一些方法

方法1:

string MachineName1 = Environment.MachineName;

方法2:

string MachineName2 = System.Net.Dns.GetHostName();

方法三:

string MachineName3 = Request.ServerVariables["REMOTE_HOST"].ToString();

方法4:-

string MachineName4 = System.Environment.GetEnvironmentVariable("COMPUTERNAME");

欲了解更多,请参阅我的博客