0
std::wstring isAdmin()
{
	SID_IDENTIFIER_AUTHORITY pIdentStruct = SECURITY_NT_AUTHORITY;
	PSID ptrSidStruct;
	BOOL isMember = false;

	if (!AllocateAndInitializeSid(&pIdentStruct, 2,SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &ptrSidStruct))
	{
		return L"Unable to allocate & initialize SID struct";
	}
	if (!CheckTokenMembership( 0, ptrSidStruct, &isMember))
	{
		FreeSid(ptrSidStruct);
		return L"You do not have administrator priveledges.";
	}
	else
	{
		FreeSid(ptrSidStruct);
		return L"You have administrator privledges!";
	}
}

the above code is suppose to check if the user has admin priveleges or not...i think it is not working properly because everytime i run the code i get the "You have admin privledges" string...even if the program is not run as /right mouse click /run as asministrator

any ideas? thx

Edited by lochnessmonster: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by mitrmkar
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.