// Open a handle to the access token for the calling process.
CString str;
if (!OpenProcessToken( GetCurrentProcess(),
TOKEN_QUERY,
&hToken ))
{
str.Format("OpenProcessToken Error %u\n", GetLastError());
AfxMessageBox(str);
return FALSE;
}
// Call GetTokenInformation to get the buffer size.
// Loop through the group SIDs looking for the administrator SID.
for(i=0; i<pGroupInfo->GroupCount; i++)
{
if ( EqualSid(pSID, pGroupInfo->Groups[i].Sid) )
{
// Lookup the account name and print it.
dwSize = MAX_NAME;
if( !LookupAccountSid( NULL,
pGroupInfo->Groups[i].Sid,
lpName,
&dwSize,
lpDomain,
&dwSize,
&SidType ) )
{
dwResult = GetLastError();
if( dwResult == ERROR_NONE_MAPPED )
strcpy( lpName, "NONE_MAPPED" );
else {
str.Format("LookupAccountSid Error %u\n", GetLastError());
AfxMessageBox(str);
return FALSE;
}
}
str.Format("Current user is a member of the %s\\%s group\n",
lpDomain, lpName );
AfxMessageBox(str);
// Find out if the SID is enabled in the token.
if (pGroupInfo->Groups[i].Attributes & SE_GROUP_ENABLED)
{
AfxMessageBox("The group SID is enabled.\n");
}
else if (pGroupInfo->Groups[i].Attributes &
SE_GROUP_USE_FOR_DENY_ONLY)
{
AfxMessageBox("The group SID is a deny-only SID.\n");
}
else
{
AfxMessageBox("The group SID is not enabled.\n");
}
}
}
if (pSID)
FreeSid(pSID);
if ( pGroupInfo )
GlobalFree( pGroupInfo );
return TRUE;