Correctly determining your computer's machine name

by Scosby Wednesday, September 23, 2009

There is an interesting problem with a NETBIOS name, it cannot be longer than 15 bytes and uses ASCII characters. So what happens when Windows allows the computer name to be up to 25 characters long? The answer is that the NETBIOS name is the truncated version of your full computer name.

This breaks Environment.MachineName, which only returns the truncated NETBIOS string. Instead, use System.Net.Dns.GetHostName method to retrieve the correct computer name.

Tags:

IT | Programming