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

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

Solution #1:

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.

Respondent: djdd87

Solution #2:

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

System.Environment.MachineName
Respondent: Wil

Solution #3:

To get fully qualified name, use:

 System.Net.Dns.GetHostEntry("").HostName
Respondent: Dynamic

Solution #4:

The My namespace contains many great “helper” functions like:

My.Computer.Name
Respondent: Nathan

Solution #5:

System.Windows.Forms.SystemInformation.ComputerName;
Respondent: Nobody

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.