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();
            }
        }
 private void EnableDisablePrivileges(TokenPrivileges privileges)
 {
     UnsafeEnableDisablePrivileges(privileges);
 }
Example #3
0
 private void EnableDisablePrivileges(TokenPrivileges privileges)
 {
     UnsafeEnableDisablePrivileges(privileges);
 }
 /// <summary>
 /// Enable a single privilege on the process.
 /// </summary>
 /// <param name="privilege"></param>
 /// <exception cref="">Throws an exception if the privilege is not present
 ///  in the privilege list of the process</exception>
 public void EnablePrivilege(TokenPrivilege privilege)
 {
     var privs = new TokenPrivileges {privilege};
     EnableDisablePrivileges(privs);
 }
Example #5
0
 /// <summary>
 /// Enable a single privilege on the process.
 /// </summary>
 /// <param name="privilege"></param>
 /// <exception cref="">Throws an exception if the privilege is not present
 ///  in the privilege list of the process</exception>
 public void EnablePrivilege(TokenPrivilege privilege)
 {
     TokenPrivileges privs = new TokenPrivileges();
     privs.Add(privilege);
     EnableDisablePrivileges(privs);
 }