Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends

Can any tell me how can i get user account type i.e suppose , Account ABC has logon
and I want to check if it has administrative Rights or not.

How can i do this ?
Posted

1 solution

I Found this Code , It returns true If User is admin else false
befor using it add Refrence System.DirectoryServices.AccountManagement
C#
public bool IsAdmin ()
{
try
{
    var userCurrent = System.DirectoryServices.AccountManagement.UserPrincipal.Current;
    var Groups = userCurrent.GetAuthorizationGroups();

    var IsPotentialAdmin = Groups.Any(p => p.Sid == new SecurityIdentifier("S-1-5-32-544"));

    return IsPotentialAdmin;
}
catch (Exception ex)
{
    // this will cause access denied if user is not admin or in "Pre-Windows 2000 combatiblity" group
    return false;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900