开发者

How can I get the current local hostname using C# or VB.NET? [duplicate]

开发者 https://www.devze.com 2023-01-11 14:46 出处:网络
This question already has answers here: How do I get the computer name in .NET (12 answers) Closed 5 years ago.
This question already has answers here: How do I get the computer name in .NET (12 answers) Closed 5 years ago.

I need to get the host name currently running the a开发者_高级运维pplication. Any idea?


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).

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

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

Or you can use:

System.Environment.GetEnvironmentVariable("COMPUTERNAME");

Which will return the full computer name set during installation.


Unless I am mistaken on what you want to do..

System.Environment.MachineName


To get fully qualified name, use:

 System.Net.Dns.GetHostEntry("").HostName


The My namespace contains many great "helper" functions like:

My.Computer.Name


System.Windows.Forms.SystemInformation.ComputerName;
0

精彩评论

暂无评论...
验证码 换一张
取 消