111,126
社区成员
发帖
与我相关
我的任务
分享
string userName = System.Environment.UserName;
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();
}
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";
}