C

Check if user is an administrator in C

AllocateAndInitializeSid – allocates and initializes a security identifier (SID) with up to eight subauthorities.

CheckTokenMembership – determines whether a specified security identifier (SID) is enabled in an access token.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <stdbool.h>
 
bool isAdmin(void){
  BOOL isadmin = false;
  SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
  PSID AdministratorsGroup;
 
  isadmin = AllocateAndInitializeSid(
      &NtAuthority, 2,
      SECURITY_BUILTIN_DOMAIN_RID,
      DOMAIN_ALIAS_RID_ADMINS,
      0, 0, 0, 0, 0, 0,
      &AdministratorsGroup);
 
  if(isadmin){
      if (!CheckTokenMembership( NULL, AdministratorsGroup, &isadmin))
    	  isadmin = false;
      FreeSid(AdministratorsGroup);
  }
  return isadmin;
}
 
int main(void) {
	printf("%s\n", isAdmin()==true?"User is an administrator.":
                          "User doesn't belong to administrators Group.");
	return EXIT_SUCCESS;
}