Demand PrincipalPermission : PrincipalPermission : Security C# Source Code


Custom Search

C# Source Code » Security » PrincipalPermission »

 

Demand PrincipalPermission








    
 
using System;
using System.Security;
using System.Security.Principal;
using System.Security.Permissions;


class Class1 {
    static void Main(string[] args) {
        //AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
        WindowsIdentity wi = WindowsIdentity.GetCurrent();
        PrincipalPermission PrincipalPerm = new PrincipalPermission(wi.Name, "Administrator");

        try {
            PrincipalPerm.Demand();
            Console.WriteLine("Code demand for an administrator succeeded.");
        } catch (SecurityException e) {
            Console.WriteLine("Demand for administrator failed!");
            Console.WriteLine(e.Message);
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Security
» PrincipalPermission