private unsafe void UnsafeEnableDisablePrivileges(TokenPrivileges privileges) { byte[] privBytes = privileges.GetNativeTokenPrivileges(); fixed(byte *priv = privBytes) { Win32.SetLastError(Win32.SUCCESS); BOOL rc = Win32.AdjustTokenPrivileges( _handle, Win32.FALSE, (IntPtr)priv, 0, IntPtr.Zero, out uint cbLength); Win32.CheckCall(rc); // Additional check: privilege can't be added, and in that case, // rc indicates a success, but GetLastError() has a specific meaning. if (Marshal.GetLastWin32Error() == Win32.ERROR_NOT_ALL_ASSIGNED) { Win32.ThrowLastError(); } } }
private unsafe void UnsafeEnableDisablePrivileges(TokenPrivileges privileges) { byte[] privBytes = privileges.GetNativeTokenPrivileges(); fixed (byte* priv = privBytes) { UInt32 cbLength; Win32.SetLastError(Win32.SUCCESS); BOOL rc = Win32.AdjustTokenPrivileges( _handle, Win32.FALSE, (IntPtr) priv, 0, IntPtr.Zero, out cbLength); Win32.CheckCall(rc); // Additional check: privilege can't be added, and in that case, // rc indicates a success, but GetLastError() has a specific meaning. if (Marshal.GetLastWin32Error() == Win32.ERROR_NOT_ALL_ASSIGNED) Win32.ThrowLastError(); } }