Windows Security API

AdjustTokenPrivileges

Enables or disables privileges in the specified access token.

BOOL AdjustTokenPrivileges(
    HANDLE TokenHandle,
    BOOL DisableAllPrivileges,
    PTOKEN_PRIVILEGES NewState,
    DWORD BufferLength,
    PTOKEN_PRIVILEGES PreviousState,
    PDWORD ReturnLength
);
ParameterDescription
TokenHandleHandle to the access token.
DisableAllPrivilegesIf TRUE, disables all privileges.
NewStatePointer to a TOKEN_PRIVILEGES structure.
BufferLengthSize of the buffer pointed to by PreviousState.
PreviousStateReceives previous state of privileges.
ReturnLengthReceives required size of the buffer.

TOKEN_PRIVILEGES Structure

OpenProcessToken

Opens the access token associated with a process.

BOOL OpenProcessToken(
    HANDLE ProcessHandle,
    DWORD DesiredAccess,
    PHANDLE TokenHandle
);
ParameterDescription
ProcessHandleHandle to the process.
DesiredAccessAccess rights requested for the token.
TokenHandleReceives the token handle.

Related: GetTokenInformation

LookupPrivilegeValue

Retrieves the locally unique identifier (LUID) used on a specified system to locally represent the specified privilege name.

BOOL LookupPrivilegeValue(
    LPCWSTR lpSystemName,
    LPCWSTR lpName,
    PLUID lpLuid
);
ParameterDescription
lpSystemNameName of the system; NULL for the local system.
lpNameName of the privilege, e.g., "SeShutdownPrivilege".
lpLuidReceives the LUID for the privilege.

See also: Privilege Constants

SetTokenInformation

Sets information in an access token.

BOOL SetTokenInformation(
    HANDLE TokenHandle,
    TOKEN_INFORMATION_CLASS TokenInformationClass,
    LPCVOID TokenInformation,
    DWORD TokenInformationLength
);
ParameterDescription
TokenHandleHandle to the token to modify.
TokenInformationClassType of information to set.
TokenInformationPointer to the information buffer.
TokenInformationLengthSize of the information buffer in bytes.

Examples: Setting Privileges Example