Android_UEFIInstaller.Win32Native.AdjustTokenPrivileges C# (CSharp) Метод

AdjustTokenPrivileges() приватный Метод

private AdjustTokenPrivileges ( IntPtr TokenHandle, [ DisableAllPrivileges, TOKEN_PRIVILEGES &NewState, UInt32 BufferLengthInBytes, TOKEN_PRIVILEGES &PreviousState, UInt32 &ReturnLengthInBytes ) : bool
TokenHandle System.IntPtr
DisableAllPrivileges [
NewState TOKEN_PRIVILEGES
BufferLengthInBytes System.UInt32
PreviousState TOKEN_PRIVILEGES
ReturnLengthInBytes System.UInt32
Результат bool
        public static extern bool AdjustTokenPrivileges(IntPtr TokenHandle,
            [MarshalAs(UnmanagedType.Bool)]bool DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState,  UInt32 BufferLengthInBytes, ref TOKEN_PRIVILEGES PreviousState, out UInt32 ReturnLengthInBytes);

Usage Example

Пример #1
0
        Boolean EnablePrivilege(IntPtr HANDLE, string lpszPrivilege)
        {
            if (!Win32Native.LookupPrivilegeValue(null, lpszPrivilege, out luid))
            {
                return(false);
            }

            tp.PrivilegeCount = 1;
            tp.Luid           = luid;
            tp.Attributes     = Win32Native.SE_PRIVILEGE_ENABLED;

            uint retlen;
            uint buflen = (uint)System.Runtime.InteropServices.Marshal.SizeOf(tp2);

            //if (!Win32Native.AdjustTokenPrivileges(HANDLE, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero))
            if (!Win32Native.AdjustTokenPrivileges(HANDLE, false, ref tp, buflen, ref tp2, out retlen))
            {
                return(false);
            }

            if (System.Runtime.InteropServices.Marshal.GetLastWin32Error() != ERROR_NOT_ALL_ASSIGNED)
            {
                var win32Exception = new System.ComponentModel.Win32Exception();
                //throw new InvalidOperationException("AdjustTokenPrivileges failed.", win32Exception);
                return(false);
            }

            return(true);
        }