如何使用C#或VB.NET获取当前的本地主机名? [英] How can I get the current local hostname using C# or VB.NET?

查看:44
本文介绍了如何使用C#或VB.NET获取当前的本地主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取当前正在运行该应用程序的主机名.有什么主意吗?

I need to get the host name currently running the application. Any idea?

推荐答案

需要记住的是 System.Environment.MachineName; System.Windows.Forms.SystemInformation.ComputerName; 将为您提供计算机的NETBIOS名称(限制为15个字符).

Something to bear in mind is that System.Environment.MachineName; and System.Windows.Forms.SystemInformation.ComputerName; will give you the NETBIOS name of the machine (restricted to 15 characters).

如果要使用完整的基于TCP/IP的主机名,可以使用 Dns.GetHostName() :

If you want the full TCP/IP based host name you can use Dns.GetHostName():

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

或者您可以使用:

System.Environment.GetEnvironmentVariable("COMPUTERNAME");

这将返回安装过程中设置的完整计算机名称.

Which will return the full computer name set during installation.

这篇关于如何使用C#或VB.NET获取当前的本地主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆