Environment Class
The Environment class is found in the System namespace. It provides details of the current environment and operating system settings and allows some of this information to be modified. The Environment class contains a read-only static property named MachineName that returns a string containing the NetBIOS name of the local computer.
The name returned is that which was assigned to the computer during installation of Windows and possibly changed using the network settings in the Windows Control Panel. This name is read from the registry when the operating system starts. If the name has been changed and the computer has not since been rebooted, the name returned may be incorrect.
NB: If the machine is a server that is a node in a cluster, the name of the machine, not the cluster, is returned.
The following outputs the name of the current machine to the console.
Console.WriteLine(Environment.MachineName);
5 October 2008