我要写三个 click 事件,来显示三个信息,用 GetUserName(); 显示错误。应该怎么写才适合XP,VISTA 和WIN7系统显示这三个系统用户信息。。代码如下。。我应该怎样写?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace CC
{
   public partial class Home : Form
   {
   public Home()
   {
   InitializeComponent();
   }   private void pictureBox1_Click(object sender, EventArgs e)
   {
   //show user account picture
   }   private void label1_Click(object sender, EventArgs e)
   {
   //show user account Name  
  }   private void label2_Click(object sender, EventArgs e)
   {
   // show user account Type
   }
   }
}

解决方案 »

  1.   

    就是你按电脑的“开始”菜单的时候,你会看到一个小图片,还有当前的用户名,和该用户的类型,即是系统管理员,还是超级用户,我现在想在窗口的 pictureBox1显示那个小图片,label1直接显示用户名,label2显示该用户的类型。
      

  2.   

    1.获得当前用户名:
    using System.Management;                SelectQuery query = new SelectQuery("select * from Win32_UserAccount where Name='" + System.Environment.UserName + "'");
                    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                    foreach (ManagementObject envVar in searcher.Get())
                    {
                        string fullName = envVar["FullName"].ToString();
                    }
    2。获得当前用户权限(参考了 http://pcheruku.wordpress.com/2008/07/31/sample-c-code-to-get-user-login-type/)
    using System.Security.Principal;WindowsIdentity ident = WindowsIdentity.GetCurrent();
    WindowsPrincipal principal = new WindowsPrincipal(ident);string userType = "";
    if (principal.IsInRole(WindowsBuiltInRole.Administrator))
    {
        userType = "Administrator";
    }
    else if (principal.IsInRole(WindowsBuiltInRole.PowerUser))
    {
        userType = "Power User";
    }
    else if (principal.IsInRole(WindowsBuiltInRole.User))
    {
        userType = "User";
    }
    else if (principal.IsInRole(WindowsBuiltInRole.Guest))
    {
        userType = "Guest";
    }
    3.获取用户图片,参考http://go4answers.webhost4life.com/Example/get-windows-user-account-name-picture-77793.aspx
      

  3.   


       string userName = System.Environment.UserName;