Click here to Skip to main content
15,886,830 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

How to find if a user is administrator or not

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
6 Dec 2011CPOL 6.1K   1  
It's quite common to find out whether a user or application is running Admin account or not.CodeProject already has excellent tips focusing a nice way to accomplish the same task.Have a look at the CodeProject links.Tips posted by John Is Your App Running As Administrator?[^] and Sam...
It's quite common to find out whether a user or application is running Admin account or not.
CodeProject already has excellent tips focusing a nice way to accomplish the same task.
Have a look at the CodeProject links.

Tips posted by John Is Your App Running As Administrator?[^] and Sam Cragg gives an excellent alternate tip to John's tip.
Sam tries to focus on how to use the application manifest file (It works only in VS2010).
<requestedexecutionlevel level="requireAdministrator" uiaccess="false" />


Alternate Tip Link: Is Your App Running As Administrator?(AlternateTip By Cragg)[^]

Reference Link: http://msdn.microsoft.com/en-us/library/bb756929.aspx[^]

In addition, I've also posted my code in another forum which focuses on the same concept.
Admin Check[^]

In addition to the above reference, you can use the given code also to find out whether the user is Admin or not. Just use System.DirectoryServices.AccountManagement:

public static bool IsAdmin()
      {
          bool isAllowed = false;
          using (PrincipalContext pc = new PrincipalContext(ContextType.Machine, null))
          {
              UserPrincipal up = UserPrincipal.Current;
              GroupPrincipal gp = GroupPrincipal.FindByIdentity(pc, "Administrators");
              if (up.IsMemberOf(gp))
                  isAllowed = true;
          }
          return isAllowed;
      }


Reference Link: MSDN-[System.DirectoryServices.AccountManagement][^]

License

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


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --