我怎样才能使用C#或VB.NET当前本地主机名? [英] How Can i Get the Current Local Host Name using C# or VB.NET?

查看:117
本文介绍了我怎样才能使用C#或VB.NET当前本地主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的主机名当前运行的应用程序。 ?任何想法

I need to get the host name currently running the application. Any idea?

推荐答案

东西要记住的是, System.Environment.MachineName; System.Windows.Forms.SystemInformation.ComputerName; 会给你的机器的NETBIOS名称(仅限于15个字符)。

Something to bear in mind is that System.Environment.MachineName; and System.Windows.Forms.SystemInformation.ComputerName; will give you the NETBIOS name of the machine (restricted to 15 characters).

如果你想完整的TCP / IP的主机名称可以使用的 Dns.GetHostName()

If you want the full TCP/IP based host name you can use Dns.GetHostName():

string hostName = System.Net.Dns.GetHostName();



或者你可以使用:

Or you can use:

System.Environment.GetEnvironmentVariable("COMPUTERNAME");



这将返回完整计算机名称在安装过程中设置的。

Which will return the full computer name set during installation.

这篇关于我怎样才能使用C#或VB.NET当前本地主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆