How can I get "computer name" and "Full computer name" using C #?
What are shown in the properties of the computer:
What you refer to as the full name is actually the MachineName
and the HostName
name. You can do it this way:
static void Main(string[] args)
{
var nome = Environment.MachineName;
var nomeCompleto = Dns.GetHostEntry(nome).HostName;
Console.WriteLine(nome); //PC-162
Console.WriteLine(nomeCompleto); //PC-162.meudominio.com.br
Console.Read();
}
To get the computer name just use the class Environment
static void Main(string[] args)
{
var name = Environment.MachineName;
Console.WriteLine("Nome do computador: {0}", name);
Console.ReadLine();
}
To get the name of the machine use Environment.MachineName
:
class Sample
{
public static void Main()
{
Console.WriteLine("Nome: {0}", Environment.MachineName);
}
}
Link: link
I think it's using the "Environment.MachineName", but I can not confirm because I'm trying to get the same as you