This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

System Information
.NET 1.1+

Getting the Current Machine Name

When an application's user performs certain actions you may want to log details for auditing purposes. For networked software it can be useful to retain the name of the user's local computer. This name can be obtained using the .NET framework.

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.

5 October 2008