Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To Admin or not to Admin
Message
General information
Forum:
ASP.NET
Category:
Security
Miscellaneous
Thread ID:
00808611
Message ID:
00808652
Views:
13
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal princ = (WindowsPrincipal)System.Threading.Thread.CurrentPrincipal;
if (princ.IsInRole(WindowsBuiltInRole.Administrator))
	Console.Write("You are admin!");
Use can also check IsInRole using Attributes. This is called declarative security and is the preferred way:
[PrincipalPermissionAttribute(SecurityAction.Demand, Role=@"DOMAINNAME\Administrators")]
public sealed class OnlyAdminsCanCallMe
{
}
The security demand will throw an exception that you can catch.

>Hello UT,
> How can you tell if the currently logged in user has admin rights on the local machine? I don't need to modify I only need to read. I have some application functions that I want to disable if the user doesn't have admin over the local machine. I was also hoping to avoid attempting an admin only activity to see if it fails.
>
>My Thanks in advance,
Previous
Reply
Map
View

Click here to load this message in the networking platform