+ Reply to Thread
Results 1 to 2 of 2

Thread: How can I find whether current user is Administrator or not?

  1. #1

    How can I find whether current user is Administrator or not?

    How can I find whether current user is Administrator or not?

  2. #2
    Following is the example:

    Code:
    BOOL AmIAdmin()
    {
    	SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY ;
    	PSID AdministratorsGroup ;
    	BOOL bResult = AllocateAndInitializeSid(&NtAuthority,
    											2,
    											SECURITY_BUILTIN_DOMAIN_RID,
    											DOMAIN_ALIAS_RID_ADMINS,
    											0, 0, 0, 0, 0, 0,
    											&AdministratorsGroup) ;
    	if(bResult) 
    	{
    		if (!CheckTokenMembership( NULL, AdministratorsGroup, &bResult)) 
    		{
    			bResult = FALSE ;
    		} 
    		FreeSid(AdministratorsGroup) ;
    	}
    	
    	return bResult ;
    }
    
    void IsAdmin()
    {
    	//PART 1 IsUserAnAdmin:
    	//http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/845d7e49-5c5f-4da7-b1c8-ddf6dc0c6541/
    	BOOL bAmIAdmin = IsUserAnAdmin() ;
    
    	//PART 2 : 
    	bAmIAdmin = AmIAdmin() ;
    }
    Note:
    IsUserAnAdmin API may/may not work. For more information visit below:
    http://social.msdn.microsoft.com/For...-ddf6dc0c6541/

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts