Esempio n. 1
0
        public static void AdjustPrivileges(this AdvApi32.SafeTokenHandle hObj, AdvApi32.PTOKEN_PRIVILEGES privileges)
        {
            if (privileges == null)
            {
                return;
            }
            uint retLen = 0;

            if (!AdvApi32.AdjustTokenPrivileges(hObj, false, privileges, (uint)privileges.SizeInBytes, null, ref retLen))
            {
                throw new Win32Exception();
            }
        }
Esempio n. 2
0
        public static SafeCoTaskMemHandle AdjustPrivilege(this AdvApi32.SafeTokenHandle hObj, SystemPrivilege priv, AdvApi32.PrivilegeAttributes attr)
        {
            var newState  = new AdvApi32.PTOKEN_PRIVILEGES(priv.GetLUID(), attr);
            var prevState = AdvApi32.PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance();
            var retLen    = (uint)prevState.Size;

            if (!AdvApi32.AdjustTokenPrivileges(hObj, false, newState, newState.SizeInBytes, prevState, ref retLen))
            {
                throw new Win32Exception();
            }
            prevState.Resize((int)retLen);
            return(prevState);
        }
Esempio n. 3
0
        public static SafeCoTaskMemHandle AdjustPrivileges(this AdvApi32.SafeTokenHandle hObj, params ExtensionMethods.PrivilegeAndAttributes[] privileges)
        {
            if (privileges == null || privileges.Length == 0)
            {
                return(SafeCoTaskMemHandle.Null);
            }
            var newState  = new AdvApi32.PTOKEN_PRIVILEGES(privileges.Select(pa => new AdvApi32.LUID_AND_ATTRIBUTES(pa.Privilege.GetLUID(), pa.Attributes)).ToArray());
            var prevState = AdvApi32.PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance();
            var retLen    = (uint)prevState.Size;

            if (!AdvApi32.AdjustTokenPrivileges(hObj, false, newState, newState.SizeInBytes, prevState, ref retLen))
            {
                throw new Win32Exception();
            }
            prevState.Resize((int)retLen);
            return(prevState);
        }