This should do it...
using System;
using System.Management;
using System.Windows.Forms;
namespace MyComputerName
{
public class GetComputerName
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("Client Computer Name is : {0}", queryObj["Name"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("Oops ! ERROR : " + e.Message);
}
}
}
}