C# winForm 中有什么方法可获得当前的计算机名?
2个回答
展开全部
System.Net
public void DisplayLocalHostName()
{
try {
// Get the local computer host name.
String hostName = Dns.GetHostName();
Console.WriteLine("Computer name :" + hostName);
}
catch(SocketException e) {
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
}
public void DisplayLocalHostName()
{
try {
// Get the local computer host name.
String hostName = Dns.GetHostName();
Console.WriteLine("Computer name :" + hostName);
}
catch(SocketException e) {
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询