Monday, April 25, 2011

How do I get the local machine Name?

How do I get the local machine name?

From stackoverflow
  • System.Environment.MachineName

    Joel Coehoorn : Beat me by 14 seconds.
    annakata : Sorry :) These little questions are kind of a turkey shoot. I kind of assumed there'd be 4 answers by the time I posted.
    annakata : Well *now* I feel guilty about ridiculous amount of upvotes...
    Joel Coehoorn : Hehe. Don't worry: we'd both likely crack the 200/day cap without them anyway.
    dnewcome : I really didn't mean anything much by the comment on my post. Just expressing a `doh' moment.
  • You should be able to use System.Environment.MachineName for this. It is a property that returns a string containing the netBIOS name of the computer:

    http://msdn.microsoft.com/en-us/library/system.environment.machinename.aspx

    dnewcome : LOL I guess I shouldn't have taken the extra few seconds to link the MSDN article.
    Rowland Shaw : But it's a more complete answer, so you'll still gain some upvotes...
    annakata : No hard feelings +1 - SO is just like that
  • From link text

    Four ways to get your local network/machine name:

    string name = Environment.MachineName;
    string name = System.Net.Dns.GetHostName();
    string name = System.Windows.Forms.SystemInformation.ComputerName;
    string name = System.Environment.GetEnvironmentVariable(“COMPUTERNAME”);
    
    epotter : Do they return the same thing or is there some difference between all of them?

0 comments:

Post a Comment