标签:
1 BOOL GetUserSID(CString &Sid) 2 { 3 HANDLE hProcess = GetCurrentProcess(); 4 5 if (hProcess) 6 { 7 HANDLE hToken; 8 9 if (OpenProcessToken(hProcess, TOKEN_QUERY, &hToken) && hToken) 10 { 11 BYTE tagTokenInfoBuf[256]; 12 PTOKEN_USER tagTokenInfo = (PTOKEN_USER)&tagTokenInfoBuf; 13 14 if (GetTokenInformation(hToken, TokenUser, tagTokenInfoBuf, sizeof(tagTokenInfoBuf), NULL)) 15 { 16 LPTSTR MySid = NULL; 17 18 ConvertSidToStringSid(tagTokenInfo->User.Sid, &MySid); 19 Sid = MySid; 20 21 LocalFree(MySid); 22 23 return TRUE; 24 } 25 26 CloseHandle(hToken); 27 } 28 29 CloseHandle(hProcess); 30 } 31 32 return FALSE; 33 }
标签:
原文地址:http://www.cnblogs.com/crsky/p/5632666.html