;; 
;;=====================================================================================----- 
;; 
;;FUNCTION		WMISysRole()  
;;  
;;AUTHOR		Glenn Barnas 
;;  
;;ACTION		Returns the Domain Role of a local or remote system  
;;  
;;VERSION		1.0  - 2012/01/06 
;; 
;;HISTORY               1.0  - 2012/01/06 - Initial Release 
;;  
;;SYNTAX		WMISysRole([system] [,WMIAuthPtr])  
;;  
;;PARAMETERS		System - OPTIONAL - String 
;;                      - name of system to query. Default is local system  
;;  
;;REMARKS		Returns the Role ID according to the following table 
;;                       0 = Standalone Workstation 
;;                       1 = Member Workstation 
;;                       2 = Standalone Server 
;;                       3 = Member Server 
;;                       4 = Backup Domain Controller 
;;                       5 = Primary Domain Controller 
;;  
;;RETURNS		Int: ID value 
;;  
;;DEPENDENCIES		WMI 
;;  
;;TESTED WITH		Win2K, WinXP, Win2K3  
;;  
;;EXAMPLES		$Role = WMISysRole('ThatPC') 
;;                      If WMISysRole() > 1 'This computer is a SERVER' EndIf 
;;                      If WMISysRole() > 3 'This computer is a DOMAIN CONTROLLER' EndIf 
;;  
; 
Function WMISysRole(Optional $_Computer, OPTIONAL $_pAuth)
 
  Dim $_objWMIService, $_colItems, $_objItem	; WMI object vars 
  Dim $_M					; memory calculation var 
 
  ; insure a properly formatted computer name, default to local computer is not specified 
  $_Computer = IIf(Not $_Computer, '.', Join(Split($_Computer,'\'),''))
 
  ; If a pre-authenticated WMI object pointer was provided, use it, otherwise create a new object pointer 
  If $_pAuth
    $_objWMIService = $_pAuth
  Else
    $_objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Computer + '\root\cimv2')
    If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
  EndIf
 
  $_colItems = $_objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
  For each $_objItem in $_colItems
    $_M = (Val($_objItem.domainrole))
  Next
 
  $WMISysRole = $_M
  Exit @ERROR
 
EndFunction