;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       GetAdminName() 
;; 
;;ACTION         Returns the localized name for a specified admin user or group 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0 - 2020/03/15 
;; 
;;HISTORY        1.0 - 2020/03/15 - Initial Release 
;; 
;;SYNTAX         GetAdminName(name) 
;; 
;;PARAMETERS     Name - REQUIRED - The English name of the User or Group to identify 
;; 
;;REMARKS        Supports the following: Administrator, Administrators, Domain Admins, Enterprise Admins, Schema Admins 
;; 
;;RETURNS        Name in localized Language, or array of all 5 standard names in the above order 
;; 
;;DEPENDENCIES   WMI 
;; 
;;TESTED WITH    W2K8, W2K12, W2K16 
;; 
;;EXAMPLES        
; 
Function GetAdminName(OPTIONAL $_Name)
 
  Dim $_aNames, $_aTypes, $_aScopes, $_aGroups			        ; data arrays 
  Dim $_Group, $_Type, $_Scope, $_Check                                 ; Config vars 
  Dim $_oWMIService, $_cItems, $_oItem                                  ; WMI vars 
  Dim $_I, $_aTmp[4]
  
  $_aNames  = 'Administrator', 'Administrators', 'Domain Admins', 'Enterprise Admins', 'Schema Admins'
  $_aTypes  = 0, 1, 1, 1, 1
  $_aScopes = -1, -1, 0, 0, 0
  $_aGroups = '*-500', 'S-1-5-32-544', '*-512', '*-519', '*-518'
 
  $_oWMIService = GetObject('winmgmts:\\.\root\cimv2')
 
  If Not $_Name
    ; Return the standard results if LOCALE is English 
    If InStr(ReadValue('HKEY_CURRENT_USER\Control Panel\International', 'LocaleName'), 'xen-')
      $GetAdminName = $_aNames
      $_oWMIService = 0
      Exit 0
    EndIf
 
    For $_I = 0 to UBound($_aNames)
 
      Select
       Case $_I = 0
        $_cItems = $_oWMIService.ExecQuery('Select SID,Name from Win32_UserAccount Where LocalAccount=-1 and SID Like "%-500"',,48)
        For Each $_oItem in $_cItems $_aTmp[$_I] = $_oItem.Name Next
       Case $_I = 1
        $_cItems = $_oWMIService.ExecQuery('Select SID,Name from Win32_Group Where LocalAccount=-1 And SID="S-1-5-32-544"',,48)
        For Each $_oItem in $_cItems $_aTmp[$_I] = $_oItem.Name Next
       Case $_I = 2
        $_cItems = $_oWMIService.ExecQuery('Select SID,Name from Win32_Group Where SID Like "%-5[0-1][0289]" And LocalAccount=0',,48)
        For Each $_oItem in $_cItems
          $_Group = $_aGroups[$_I]
          If Left($_Group, 1) = '*'
            $_Check = SubStr($_Group, 2)
            If $_Check = Right($_oItem.SID, Len($_Check))
              $_aTmp[$_I] = $_oItem.Name
            EndIf
          Else
            If $_Group = $_oItem.SID
              $_aTmp[$_I] = $_oItem.Name
            EndIf
          EndIf
          $_I = $_I + 1
        Next
      EndSelect
    Next
    $GetAdminName = $_aTmp
    $_oWMIService = 0
    Exit 0
  Else  
    $_I = AScan($_aNames, $_Name)
    If $_I < 0 Exit 87 EndIf						; Not Found - invalid name 
    $_Type  = $_aTypes[$_I]
    $_Scope = $_aScopes[$_I]
    $_Group = $_aGroups[$_I]
 
    If $_Type                                                             ; Group 
      $_cItems = $_oWMIService.ExecQuery('Select SID,Name from Win32_Group Where LocalAccount=' + $_Scope,,48)
    Else                                                                  ; User 
      $_cItems = $_oWMIService.ExecQuery('Select SID,Name from Win32_UserAccount Where LocalAccount=' + $_Scope,,48)
    EndIf
 
    For Each $_oItem in $_cItems
      If Left($_Group, 1) = '*'
        $_Check = SubStr($_Group, 2)
        If $_Check = Right($_oItem.SID, Len($_Check))
          $GetAdminName = $_oItem.Name
          $_oWMIService = 0
          Exit 0
        EndIf
      Else
        If $_Group = $_oItem.SID
          $GetAdminName = $_oItem.Name
          $_oWMIService = 0
          Exit 0
        EndIf
      EndIf
    Next
  EndIf
  
  $_oWMIService = 0
 
  Exit 2
 
EndFunction