How to find if the logged user is a admin or not?

Just saw a mail over an internal alias showing off how to find out if the currently logged on user is an admin… we make this reasonably easy in Whidbey.

using System;

using System.Security.Principal;

class Test

{

    public static void Main()

    {

        if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))

        {

            Console.WriteLine("I am an admin.");

        }

    }

}