Benutzername und Benutzerolle ausgeben

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 = &quot;account operator&quot;;
            else
                if (principle.IsInRole(WindowsBuiltInRole.Administrator)) role = &quot;administrator&quot;;
                else
                    if (principle.IsInRole(WindowsBuiltInRole.BackupOperator)) role = &quot;backup opearator&quot;;
                    else
                        if (principle.IsInRole(WindowsBuiltInRole.Guest)) role = &quot;guest&quot;;
                        else
                            if (principle.IsInRole(WindowsBuiltInRole.PowerUser)) role = &quot;power user&quot;;
                            else
                                if (principle.IsInRole(WindowsBuiltInRole.User)) role = &quot;user&quot;;
                                else
                                    if (principle.IsInRole(WindowsBuiltInRole.PrintOperator)) role = &quot;print operator&quot;;
                                    else
                                        if (principle.IsInRole(WindowsBuiltInRole.Replicator)) role = &quot;replicator&quot;;
                                        else
                                            if (principle.IsInRole(WindowsBuiltInRole.SystemOperator)) role = &quot;system operator&quot;;

            return role;
        }
    }
}