Example #1
0
        private unsafe void UnsafeEnableDisablePrivileges(TokenPrivileges privileges)
        {
            byte[] privBytes = privileges.GetNativeTOKEN_PRIVILEGES();
            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();
                }
            }
        }
Example #2
0
        private unsafe void UnsafeEnableDisablePrivileges(TokenPrivileges privileges)
        {
            byte[] privBytes = privileges.GetNativeTOKEN_PRIVILEGES();
            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();
            }
        }