我将如何查询当前登录用户所属的活动目录组?我假设它将通过 LDAP,但我还没有找到很多关于如何获取这些特定信息的信息。
我已经整理了一些代码,但我不太确定下一步我需要做什么
// Open the access token associated with the calling process.
if (OpenProcessToken(GetCurrentProcess(),
TOKEN_QUERY,
&hToken) == FALSE)
{
dwErrorCode = GetLastError();
wprintf(L"OpenProcessToken failed. GetLastError returned: %d\n", dwErrorCode);
return HRESULT_FROM_WIN32(dwErrorCode);
}
// Retrieve the token information in a TOKEN_USER structure.
GetTokenInformation(hToken,
TokenUser, // Request for a TOKEN_USER structure.
NULL,
0,
&dwBufferSize);
pTokenUser = (PTOKEN_USER) new BYTE[dwBufferSize];
memset(pTokenUser, 0, dwBufferSize);
if (GetTokenInformation(hToken,
TokenUser,
pTokenUser,
dwBufferSize,
&dwBufferSize))
{
CloseHandle(hToken);
}
else
{
dwErrorCode = GetLastError();
wprintf(L"GetTokenInformation failed. GetLastError returned: %d\n", dwErrorCode);
return HRESULT_FROM_WIN32(dwErrorCode);
}
if (IsValidSid(pTokenUser->User.Sid) == FALSE)
{
wprintf(L"The owner SID is invalid.\n");
delete [] pTokenUser;
}