BOOL GetUserSID(CString &Sid)
{
HANDLE hProcess = GetCurrentProcess(); if (hProcess)
{
HANDLE hToken; if (OpenProcessToken(hProcess, TOKEN_QUERY, &hToken) && hToken)
{
BYTE tagTokenInfoBuf[];
PTOKEN_USER tagTokenInfo = (PTOKEN_USER)&tagTokenInfoBuf; if (GetTokenInformation(hToken, TokenUser, tagTokenInfoBuf, sizeof(tagTokenInfoBuf), NULL))
{
LPTSTR MySid = NULL; ConvertSidToStringSid(tagTokenInfo->User.Sid, &MySid);
Sid = MySid; LocalFree(MySid); return TRUE;
} CloseHandle(hToken);
} CloseHandle(hProcess);
} return FALSE;
}