Ofer
Ofer

Reputation: 333

GetTokenInformation returns ERROR_INSUFFICIENT_BUFFER

The code below returns an ERROR_INSUFFICIENT_BUFFER error:

DWORD dwReturnedDataSize;
if (!GetTokenInformation(hToken,TokenPrivileges,NULL,0,&dwReturnedDataSize))
{
    CloseHandle(hToken);
    return false; 
}

I can't figure out why.

Upvotes: 0

Views: 1120

Answers (1)

Steve Townsend
Steve Townsend

Reputation: 54128

This is because you have called the function in the mode where it tells you how many bytes you need to retrieve the underlying Token Information data for this handle. You now need to make a second call using the returned datalength and a buffer of at least that size.

Docs are helpful.

ReturnLength [out]

A pointer to a variable that receives the number of bytes needed for the buffer pointed to by the TokenInformation parameter. If this value is larger than the value specified in the TokenInformationLength parameter, the function fails and stores no data in the buffer.

Upvotes: 5

Related Questions