Search code examples
c++windowswinapisid

How to copy SID for storage with C++


Say, if I get a user's SID with the following API:

TOKEN_USER* pTU = (TOKEN_USER*)pbytes;
DWORD dwSize;
GetTokenInformation(hToken, TokenUser, pTU, dwSize, &dwSize);

pTU->User.Sid;  //Contains the SID I need

I need to store this SID for later use/comparison in the program. But how do I copy it?

If I do this:

SID globalSIDStorage;
globalSIDStorage = *pTU->User.Sid;

I get an error that:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'PSID' (or there is no acceptable conversion.


Solution

  • You probably want to use CopySid.