System.Security.AccessControl.Privilege.RunWithPrivilege C# (CSharp) Method

RunWithPrivilege() public static method

public static RunWithPrivilege ( string privilege, bool enabled, PrivilegedHelper helper ) : void
privilege string
enabled bool
helper PrivilegedHelper
return void
        public static void RunWithPrivilege( string privilege, bool enabled, PrivilegedHelper helper )
        {
            if ( helper == null )
            {
                throw new ArgumentNullException( "helper" );
            }
            Contract.EndContractBlock();
            
            Privilege p = new Privilege( privilege );

            try 
            {
                if (enabled)
                {
                    p.Enable();
                }
                else
                {
                    p.Disable();
                }

                helper();
            }
            finally
            {
                p.Revert();
            }
        }
#endif