How to get the computer name?

Asked

Viewed 3,163 times

0

How can I get the "computer name" and "Full computer name" using C#?

Which are shown in the computer properties:

propriedades do computador

  • Why are you saying that the question is not clear or useful?

  • see my answer.

  • I’ve seen it! and it worked just like that!

4 answers

6


What you refer to as the full name is actually the MachineName and the name of HostName. You can obey him that 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();
}

1

  • 1

    @Andersoncarloswoss I’m going to go against it and say that maybe I’ll answer yes, of course the answer was quite weak, so add an example.

1

To get the name of the computer only use the class Environment

static void Main(string[] args)
{
    var name = Environment.MachineName;
    Console.WriteLine("Nome do computador: {0}", name);
    Console.ReadLine();
}
  • 1

    And how do I get the computer’s full name?

  • What do you mean "full name"?

  • 1

    on the control panel has the "Computer name" and the "Full Computer Name" and I lack this, but I can find nowhere to talk about it

0

I think it’s using "Environment.Machinename," but I can’t confirm because I’m trying to get the same thing you do

  • 1

    It is the "Environment.Machinename", works perfectly, use in your program too

  • Well, then I’ll test it! Thanks for the help.

  • 2

    two accounts of the same person, two of which have already been banned and suspended today...

  • @Rovannlinhalis, including my original answer, was to the other question :) https://answall.com/questions/309916/howto get o-full-name-do-computador-em-wpfc

  • What’s the harm after you check that it works to share the answer with those who need it? that’s not why I’m a fake account or he, I don’t understand what I’ve done wrong to the community sincerely....

  • Is it my fault I don’t want to make myself known? If I don’t have the confidence in the world to show my face, are you going to make me do it? I repeat, before accusing, know what you are talking about please that it is ugly to make completely unrealistic accusations. With this I withdraw, a friendly hug.

  • the two users exemplarily banned =] even the user’s number was close to each other, proving the creation practically at the same time

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.