First, you will have to get the current windows user identity. You can
do this by calling the static GetCurrent method on the WindowsIdentity
class. Then, pass that WindowsIdentity instance to the constructor of a
WindowsPrincipal class. With that, you can call the IsInRole method and
pass the Administrators role (a string), or you can pass in the
Administrator value from the WindowsBuiltInRole enumeration.
One thing to note here is that if you do use the string parameter option
(as opposed to the enum) you need to actually pass
"BUILTIN\Administrators" or it will not recognize it. This is true for
all of the roles in the WindowsBuiltInRole. I mention this because it
had me going for a bit when I needed it and thought I could just pass
the "Administrators" in. Just thought I'd mention it.
While you could use the CurrentPrincipal on the thread, it's not
guaranteed that it will always return a WindowsPrincipal, so you have to
watch out for it.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.