AdvApi32AdjustTokenPrivileges Method

Enables or disables privileges in the specified access token.

Enabling or disabling privileges in an access token requires AdjustPrivileges access.

Note that AdjustTokenPrivileges(IntPtr, Boolean, TokenPrivileges, Int32, TokenPrivileges, IntPtr) cannot add or remove privileges from the token. It can only enable existing privileges that are currently disabled, or disable existing privileges that are currently enabled.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("AdvApi32.dll", SetLastError = true)]
public static bool AdjustTokenPrivileges(
	IntPtr tokenHandle,
	bool disableAllPrivileges,
	ref TokenPrivileges refNewState,
	int bufferLength,
	ref TokenPrivileges refPreviousState,
	ref IntPtr refReturnLength
)

Parameters

tokenHandle  IntPtr
An IntPtr pointer handle to the access token that contains the privileges to be modified.

The handle must have AdjustPrivileges access to the token.

If the refPreviousState parameter is not , the handle must also have Query access.

disableAllPrivileges  Boolean
Specifies whether the function disables all of the token's privileges.

If this value is , the function disables all privileges and ignores the refNewState parameter.

If it is , the function modifies privileges based on the information pointed to by the refNewState parameter.

refNewState  TokenPrivileges
A IntPtr pointer to a TokenPrivileges structure that specifies an array of privileges and their attributes.

If the disableAllPrivileges parameter is , the AdjustTokenPrivileges(IntPtr, Boolean, TokenPrivileges, Int32, TokenPrivileges, IntPtr) function enables, disables, or removes these privileges for the token.

bufferLength  Int32
Specifies the size, in bytes, of the buffer pointed to by the refPreviousState parameter.

This parameter can be zero if the refPreviousState parameter is .

refPreviousState  TokenPrivileges
A pointer to a buffer that the function fills with a TokenPrivileges structure that contains the previous state of any privileges that the function modifies.

That is, if a privilege has been modified by this function, the privilege and its previous state are contained in the TokenPrivileges structure referenced by refPreviousState.

If the PrivilegeCount member is 0, then no privileges have been changed by this function.

This parameter can be .

refReturnLength  IntPtr
A pointer to a variable that receives the required size, in bytes, of the buffer pointed to by the refPreviousState parameter.

This parameter can be if refPreviousState is .

Return Value

Boolean
If the function succeeds, the return value is , otherwise, .

To determine whether the function adjusted all of the specified privileges, call GetLastWin32Error.

Remarks

See Also