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.
Namespace: DevCase.Win32.NativeMethodsAssembly: 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
)
<DllImportAttribute("AdvApi32.dll", SetLastError := true>]
Public Shared Function AdjustTokenPrivileges (
tokenHandle As IntPtr,
disableAllPrivileges As Boolean,
ByRef refNewState As TokenPrivileges,
bufferLength As Integer,
ByRef refPreviousState As TokenPrivileges,
ByRef refReturnLength As IntPtr
) As Boolean
Dim tokenHandle As IntPtr
Dim disableAllPrivileges As Boolean
Dim refNewState As TokenPrivileges
Dim bufferLength As Integer
Dim refPreviousState As TokenPrivileges
Dim refReturnLength As IntPtr
Dim returnValue As Boolean
returnValue = AdvApi32.AdjustTokenPrivileges(tokenHandle,
disableAllPrivileges, refNewState,
bufferLength, refPreviousState,
refReturnLength)
public:
[DllImportAttribute(L"AdvApi32.dll", SetLastError = true)]
static bool AdjustTokenPrivileges(
IntPtr tokenHandle,
bool disableAllPrivileges,
TokenPrivileges% refNewState,
int bufferLength,
TokenPrivileges% refPreviousState,
IntPtr% refReturnLength
)
[<DllImportAttribute("AdvApi32.dll", SetLastError = true)>]
static member AdjustTokenPrivileges :
tokenHandle : IntPtr *
disableAllPrivileges : bool *
refNewState : TokenPrivileges byref *
bufferLength : int *
refPreviousState : TokenPrivileges byref *
refReturnLength : IntPtr byref -> bool
No code example is currently available or this language may not be supported.
- 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 .
Boolean
If the function succeeds, the return value is
, otherwise,
.
To determine whether the function adjusted all of the specified privileges,
call
GetLastWin32Error.