Exemplo n.º 1
0
        public static void SetPrivilege(AccessTokenHandle handle, string privilege, bool enabled)
        {
            var newPrivs   = new List <ATPrivilege>();
            var attributes = (uint)(enabled ? Constants.SE_PRIVILEGE_ENABLED : Constants.SE_PRIVILEGE_DISABLED);

            newPrivs.Add(ATPrivilege.FromValues(privilege, attributes));

            AccessTokenPrivileges.AdjustTokenPrivileges(handle, newPrivs);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Retrieves all current thread privileges, and enables the
 /// ones that are possible.
 /// </summary>
 public static void SetAllPrivileges(AccessTokenHandle hToken, bool enabled)
 {
     foreach (var priv in Enum.GetNames(typeof(PrivilegeConstants)))
     {
         var attributes = enabled ? Constants.SE_PRIVILEGE_ENABLED : Constants.SE_PRIVILEGE_DISABLED;
         var newPriv    = new List <ATPrivilege>();
         newPriv.Add(ATPrivilege.FromValues(priv, (uint)attributes));
         try
         {
             AccessTokenPrivileges.AdjustTokenPrivileges(hToken, newPriv);
         }
         catch
         {
             continue;
         }
     }
 }