I need to get the host name currently running the application. Any idea?
+6
A:
Unless I am mistaken on what you want to do..
System.Environment.MachineName
Wil
2010-08-16 15:59:19
+6
A:
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.
GenericTypeTea
2010-08-16 16:00:08
Well, the docs are a bit vague on how it's implemented, but it is implied that it requires a) a working network connection, b) a round-trip to the DNS server, and c) that the DNS actually knows your machine name (it doesn't have to, unless your a server)
James Curran
2010-08-16 16:09:53
@James Curran - Absolutely. But Environment.MachineName restricts the computer name to a 15 character NETBIOS name. GetHostName will retrieve the full TCP/IP based hostname.
GenericTypeTea
2010-08-16 16:21:38
+1
A:
The My namespace contains many great "helper" functions like:
My.Computer.Name
Nathan
2010-08-16 18:21:20