using System.Security.Principal;
/// <summary->
/// freeware helper class for getting logon user info
/// (W) 2011 by admin of codezentrale.6x.to
/// </summary->
public static class UserInfo
{
/// <summary->
/// get logon user name
/// </summary->
public static string LogonUserName
{
get
{
return WindowsIdentity.GetCurrent().Name;
}
}
/// <summary->
/// get role of current user
/// </summary->
public static string LogonUserRole
{
get
{
string role = string.Empty;
WindowsPrincipal principle = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if (principle.IsInRole(WindowsBuiltInRole.AccountOperator)) role = "account operator";
else
if (principle.IsInRole(WindowsBuiltInRole.Administrator)) role = "administrator";
else
if (principle.IsInRole(WindowsBuiltInRole.BackupOperator)) role = "backup opearator";
else
if (principle.IsInRole(WindowsBuiltInRole.Guest)) role = "guest";
else
if (principle.IsInRole(WindowsBuiltInRole.PowerUser)) role = "power user";
else
if (principle.IsInRole(WindowsBuiltInRole.User)) role = "user";
else
if (principle.IsInRole(WindowsBuiltInRole.PrintOperator)) role = "print operator";
else
if (principle.IsInRole(WindowsBuiltInRole.Replicator)) role = "replicator";
else
if (principle.IsInRole(WindowsBuiltInRole.SystemOperator)) role = "system operator";
return role;
}
}
}