none
What namespace do i have to declare for my admin checking code? RRS feed

  • Question

  • What do i have to do to prevent this code from giving me namespace errors?

    bool IsAnAdministrator () 

    WindowsIdentity identity = 
    WindowsIdentity.GetCurrent(); 
    WindowsPrincipal principal = 
    new WindowsPrincipal (identity); 
    return principal.IsInRole 
    (WindowsBuiltInRole.Administrator); 
    }

                WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();

                WindowsPrincipal currentPrincipal = new WindowsPrincipal(currentIdentity);

                System.AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

                if (currentPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
                {
                    MessageBox.Show("Is an Administrator ");            }
                else
                {
                    MessageBox.Show(" Isn't Administrator ");
                }
    Thursday, September 17, 2009 12:39 AM

Answers

  • using System.Security.Principal;
    using System.Windows.Forms;

    Hans Passant.
    • Marked as answer by TheTrueFace Thursday, September 17, 2009 5:05 AM
    Thursday, September 17, 2009 12:46 AM
    Moderator