// Sample for the Environment.MachineName property
using System;class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
//  <-- Keep this information secure! -->
    Console.WriteLine("MachineName: {0}", Environment.MachineName);
    }
}
/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and ed "!---OMITTED---!".)MachineName: !---OMITTED---!
*/

解决方案 »

  1.   

    利用Environment类可以找到相关的信息!查MSDN有例子!
    如要取得用户名,用其属性UserName即可,上面的MachineName是取得当前机器名。具体属性查MSDN。下面列举几个常用网络上的属性:
    MachineName  获取此本地计算机的 NetBIOS 名称。
    UserDomainName  获取与当前用户关联的网络域名。
    UserName  获取启动当前线程的人的用户名。当然,该类属于System命名空间,用前请加上using System; 呵呵!
      

  2.   

    IPHostEntry myHost = new IPHostEntry();
    myHost = Dns.GetHostByName(Dns.GetHostName());
    MessageBox.Show("aada"+'\r'+myHost.HostName.ToString()+
     myHost.HostName);
    MessageBox.Show(System.Environment.UserName);
      

  3.   

    MessageBox.Show(System.Environment.MachineName) ;//本机名
      

  4.   

    还可以用api函数
    [DllImport("Advapi32.dll",  EntryPoint="GetUsername")]  
    static extern bool GetUserName (stringbuilder str,int ncount)
      

  5.   

    哦,看错了,是域中的用户名,那就应该是计算机名了,我还以为是当前用户名呢!
    [DllImport("Advapi32.dll",  EntryPoint="GetComputername")]  
    static extern bool GetComputername (stringbuilder str,int ncount)