Introduction
Many a times, when we write a simple application that accesses some system resources and if Local Security Policy needs administrative rights to run the application, then our application would just crash. For simple testing purposes too, using a MSI installer would be an involved process. Perhaps a small class to automatically check for administrative privileges of the logged on account or the account that is being used to run the application (using the RunAs utility) would be really helpful in these circumstances.
Solution
In .NET, investigating the account's principal, logged on name etc. is just a breeze. System.Security namespace has dozens of utilities and classes that really helps in getting the thing done like in the current context, checking whether the account has administrative rights etc.
Additions
The class that checks the account roles has been kept separate in the accompanying demo file from the application, since we can in the future add facilities like checking for roles, permissions and more granular level operations can be incorporated over there.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here