Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have a problem when calling GetTokenInformation,
for some reason it fails on windows server 2003 32bit but succeeds on server 2008 64bit.

C++
PTOKEN_USER pSIDTokenUser = NULL;
   DWORD       dwReturnLength;   
   
      if (!GetTokenInformation(hToken, TokenUser, NULL, 0, &dwReturnLength) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
      {
               //handle error
      }

      pSIDTokenUser = (PTOKEN_USER)new BYTE[dwReturnLength];
      memset(pSIDTokenUser, 0, dwReturnLength); 


      if (!pSIDTokenUser)
               //handle error

      if (!GetTokenInformation(hToken, TokenUser, pSIDTokenUser, dwReturnLength, NULL))
               //handle error 



the second call to GetTokenInformation on windows 2003 always return 0 with the error 998 ("Invalid access to memory location").
I assume it has something to do with the pSIDTokenUser size/alignment (I use the default) etc, but could not find the reason.

Thanks.
Posted
Comments
Matthew Faithfull 2-Jun-13 15:16pm    
I notice on your second call you don't provide anywhere for it to put the return length.
You could try:
if (!GetTokenInformation(hToken, TokenUser, pSIDTokenUser, dwReturnLength, &dwReturnLength))
I can't see any reason why this would fail to work so it's probably a bug in Windows 2003 that's been fixed.
AlphaDeltaTheta 2-Jun-13 22:11pm    
This is the bug in the code... +5 Matthew, you should have posted this as a solution

Matthew Faithfull, you are correct.
thank you for the help.
 
Share this answer
 
Quote:
Matthew Faithfull - 10 hrs ago
I notice on your second call you don't provide anywhere for it to put the return length.
You could try:
if (!GetTokenInformation(hToken, TokenUser, pSIDTokenUser, dwReturnLength, &dwReturnLength))
I can't see any reason why this would fail to work so it's probably a bug in Windows 2003 that's been fixed.


Matthew Faithfull, you are correct.
thank you for the help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900