Android_UEFIInstaller.WindowsSecurity.EnablePrivilege C# (CSharp) Method

EnablePrivilege() private method

private EnablePrivilege ( IntPtr HANDLE, string lpszPrivilege ) : System.Boolean
HANDLE System.IntPtr
lpszPrivilege string
return System.Boolean
        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;
        }