Finding Computer Name from C#

This C# code snippet obtains the NetBIOS and DNS computer names of the local computer.
It is really a useful tip which you can implement in any desktop application to find the name of the computer on which it is running from your C# code.
Useful to personalize  your application.

Code Snippet
  1. static string GetComputerName ()
  2. {
  3.    string netBiosName = System.Environment.MachineName;   
  4.    //return netBiosName;
  5.    //Following method is deprecated
  6.    //string dnsName =
  7.    //System.Net.Dns.GetHostByName("LocalHost").HostName;
  8.    string dnsName = System.Net.Dns.GetHostName();
  9.    return dnsName;
  10. }

Post a Comment