def _win_user_token_is_admin(user_token):
 class SID_IDENTIFIER_AUTHORITY(ctypes.Structure, ):
  _fields_ = [('byte0', ctypes.c_byte), ('byte1', ctypes.c_byte), ('byte2', ctypes.c_byte), ('byte3', ctypes.c_byte), ('byte4', ctypes.c_byte), ('byte5', ctypes.c_byte)]
 nt_authority = SID_IDENTIFIER_AUTHORITY()
 nt_authority.byte5 = 5
 SECURITY_BUILTIN_DOMAIN_RID = 32
 DOMAIN_ALIAS_RID_ADMINS = 544
 administrators_group = ctypes.c_void_p()
 if (ctypes.windll.advapi32.AllocateAndInitializeSid(ctypes.byref(nt_authority), 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, ctypes.byref(administrators_group)) == 0):
  raise Exception('AllocateAndInitializeSid failed')
 try:
  is_admin = ctypes.wintypes.BOOL()
  if (ctypes.windll.advapi32.CheckTokenMembership(user_token, administrators_group, ctypes.byref(is_admin)) == 0):
   raise Exception('CheckTokenMembership failed')
  return (is_admin.value != 0)
 finally:
  ctypes.windll.advapi32.FreeSid(administrators_group)

def _win_user_token_is_admin ( user_token ) : class SID_IDENTIFIER_AUTHORITY ( ctypes . Structure , ) : _fields_ = [ ( 'byte0' , ctypes . c_byte ) , ( 'byte1' , ctypes . c_byte ) , ( 'byte2' , ctypes . c_byte ) , ( 'byte3' , ctypes . c_byte ) , ( 'byte4' , ctypes . c_byte ) , ( 'byte5' , ctypes . c_byte ) ] nt_authority = SID_IDENTIFIER_AUTHORITY ( ) nt_authority . byte5 = 5 SECURITY_BUILTIN_DOMAIN_RID = 32 DOMAIN_ALIAS_RID_ADMINS = 544 administrators_group = ctypes . c_void_p ( ) if ( ctypes . windll . advapi32 . AllocateAndInitializeSid ( ctypes . byref ( nt_authority ) , 2 , SECURITY_BUILTIN_DOMAIN_RID , DOMAIN_ALIAS_RID_ADMINS , 0 , 0 , 0 , 0 , 0 , 0 , ctypes . byref ( administrators_group ) ) == 0 ) : raise Exception ( 'AllocateAndInitializeSid failed' ) try : is_admin = ctypes . wintypes . BOOL ( ) if ( ctypes . windll . advapi32 . CheckTokenMembership ( user_token , administrators_group , ctypes . byref ( is_admin ) ) == 0 ) : raise Exception ( 'CheckTokenMembership failed' ) return ( is_admin . value != 0 ) finally : ctypes . windll . advapi32 . FreeSid ( administrators_group )
using the win32 api .