How do I get the local machine name in C#?

后端 未结 5 884
梦谈多话
梦谈多话 2020-11-27 18:27

How do I get the local machine name?

5条回答
  •  天涯浪人
    2020-11-27 19:29

    My computer name is more than 15 chars, so i use hostname.exe to get full length name:

    Process proc = new Process();
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.FileName = "c:/windows/system32/hostname.exe";
    proc.Start();
    var hostName = proc.StandardOutput.ReadLine();
    

提交回复
热议问题