C++/현재 로그인한 사용자의 SID 구하기 Edit Diff Refresh Backlink Random Search History Help Setting Hide Show DWORD GetProcessIDFromName(LPTSTR szProcName) { PROCESSENTRY32 procEntry; HANDLE hSnapshot; BOOL bFound; if(!(hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0))) return 0; procEntry.dwSize = sizeof(PROCESSENTRY32); bFound = Process32First(hSnapshot, &procEntry); while(bFound) { if(!lstrcmp(procEntry.szExeFile, szProcName)) { CloseHandle(hSnapshot); return procEntry.th32ProcessID; } bFound = Process32Next(hSnapshot, &procEntry); } CloseHandle(hSnapshot); return 0; } BOOL GetCurrentUserSID(CString *csSid) { DWORD dwProcessID = GetProcessIDFromName(_T("explorer.exe")); if( 0 == dwProcessID ) { return FALSE; } #ifndef _RELEASE_WIN9X HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessID); if( hProc == NULL ) { return FALSE; } HANDLE hToken; if( !OpenProcessToken(hProc, TOKEN_QUERY, &hToken) ) { CloseHandle(hProc); return FALSE; } CloseHandle(hProc); BOOL bRet = FALSE; TOKEN_USER *pTokenUser; DWORD Len; TCHAR* pBuffer = NULL; if( !GetTokenInformation(hToken, TokenUser, NULL, 0, &Len) ) { if( GetLastError() == ERROR_INSUFFICIENT_BUFFER ) { pBuffer = new TCHAR[Len]; if( !GetTokenInformation(hToken,TokenUser, pBuffer, Len, &Len) ) { delete pBuffer; CloseHandle(hToken); return FALSE; } } else { CloseHandle(hToken); return FALSE; } } pTokenUser = (TOKEN_USER*)pBuffer; TCHAR *szStringSID; if( FALSE == ConvertSidToStringSid(pTokenUser->User.Sid, &szStringSID) ) { CloseHandle(hToken); return FALSE; } else { (*csSid).Format(_T("%s"), szStringSID); //std::string strTemp = szStringSID; LocalFree(szStringSID); //strSID = strTemp; } CloseHandle(hToken); #endif _RELEASE_WIN9X return TRUE; } CString strSid; if (GetCurrentUserSID(&strSid)) { D0(_T("%s"), strSid); } -> S-1-5-21-41567755-2767001670-2024363275-1000 C SID Win32API 윈도우 이 글에는 0 개의 댓글이 있습니다. Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus