SetTokenInformation

  BOOL SetTokenInformation(TokenHandle, TokenInformationClass, TokenInformation, TokenInformationLength)    
  HANDLE TokenHandle;    
  TOKEN_INFORMATION_CLASS TokenInformationClass;    
  LPVOID TokenInformation;    
  DWORD TokenInformationLength;    

The SetTokenInformation function sets various types of information for a specified token. The information the function sets replaces existing information. The caller must have appropriate access privileges to set the information, as noted below in the discussion of the TokenInformation parameter

Parameters

TokenHandle

Handle to the token whose information the function will set.

TokenInformationClass

Specifies the type of token information the function will set. TOKEN_INFORMATION_CLASS is an enumerated type. Possible values, some of them invalid as regards this function, are listed in the discussion of the TokenInformation parameter.

TokenInformation

Pointer to a buffer that contains the information the function will set into the token. The buffer must be aligned on at a longword boundary. The type of data structure the buffer contains depends upon the type of information specified by the TokenInformationClass parameter, as shown in this list:

Token Information Class Structure Provided In Buffer

TokenUser  
  Not valid. This function cannot set a token's user ID.
TokenGroups  
  Not valid. This function cannot set a token's group IDs.
TokenPrivileges  
  Not valid. This function cannot set a token's privilege information. However, the AdjustTokenPrivileges function can explicitly enable and disable a token's privileges.
TokenOwner  
  TOKEN_OWNER data structure. TOKEN_ADJUST_DEFAULT access is needed to set a token's owner information. A valid owner value is a user or group ID having an attribute that allows assignment as the owner of objects. The TOKEN_OWNER data structure has the following form:
  typedef struct _TOKEN_OWNER { /* to */
PSID Owner;
} TOKEN_OWNER ;
TokenPrimaryGroup  
  TOKEN_PRIMARY_GROUP data structure. TOKEN_ADJUST_DEFAULT access is needed to set a token's primary group information.
  The TOKEN_PRIMARY_GROUP data structure has the following form:
  typedef struct _TOKEN_PRIMARY_GROUP {
PSID PrimaryGroup;
} TOKEN_PRIMARY_GROUP ;
TokenDefaultDacl  
  TOKEN_DEFAULT_DACL data structure. TOKEN_ADJUST_DEFAULT access is needed to set a token's default discretionary ACL information. The ACL provided as a new default discretionary ACL is not validated for structural correctness or consistency. If TokenInformation, the pointer to the new default ACL, is null, then the current default DACL is removed and no replacement is established.
  The TOKEN_DEFAULT_DACL data structure has the following form:
  typedef struct _TOKEN_DEFAULT_DACL {
PACL DefaultDacl;
} TOKEN_DEFAULT_DACL ;
TokenSource  
  Not valid. This function cannot set a token's source name and context handle information.
TokenType  
  Not valid. This function cannot set a token's type information. The token type can only be set when the token is created.
TokenImpersonationLevel  
  Not valid. This function cannot set a token's impersonation level information. The token impersonation level can only be set when the token is created.

TokenInformationLength

Specifies the length in bytes of the buffer pointed to by TokenInformation.

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.

See Also

AdjustTokenGroups, AdjustTokenPrivileges, GetTokenInformation, OpenProcessToken, GetTokenInformation