;; 
;;=====================================================================================----- 
;; 
;;FUNCTION      ADSIObjectInfo() 
;;		Can replace ADSIUserInfo() 
;; 
;;ACTION        Get or Set an AD object attribute via ADSI 
;; 
;;AUTHOR        Glenn Barnas 
;; 
;;VERSION       1.0  - 2013/11/01 
;; 
;;History       1.0  - 2013/11/01 - Initial Release 
;; 
;;SYNTAX        ADSIObjectInfo([Object] [, Attribute] [, Value]) 
;; 
;;PARAMETERS    Object - 	OPTIONAL - AD Distinguished name. Defaults to current user 
;;		Can be "USER" or "COMPUTER" to return the current or active User or 
;;              Computer DN string. 
;; 
;;              Attribute - 	OPTIONAL - Attribute value to read or set. If Object and 
;;              Attribute are both null, the current user's DN will be returned. If an 
;;              Object name is specified and Attribute is null, and error is returned. 
;; 
;;              Value - 	OPTIONAL - Value to set 
;; 
;;REMARKS       Returns AD attribute value (including what was just set) 
;;              Sets an AD attribute value 
;; 
;;RETURNS       String - value of defined attribute or UserDN if no args are specified 
;; 
;;DEPENDENCIES  none 
;; 
;;TESTED WITH   W2K, WXP, W2K3, Vista, Win7, Win8, Server 2008, Server 2012 
;; 
;;EXAMPLES      None 
; 
Function ADSIObjectInfo(OPTIONAL $_Object, OPTIONAL $_Attr, OPTIONAL $_Value)
 
  Dim $_				; temporary var 
  Dim $_I				; index var 
  Dim $_AValid				; valid array data flag 
  Dim $_D				; "$" character 
  Dim $_oObject				; User object pointer 
  Dim $_Cmd				; execute command string 
  Dim $_RtnVal				; data returned from Execute 
  Dim $_objSysInfo 			; object pointer 
 
  $_D = Chr(36)
 
  ; If the Object is blank or "User" or "Computer", determine and return the appropriate DN string 
  ; for the local user or computer account 
  Select
   Case $_Object = '' Or $_Object = 'User'
    $_objSysInfo = CreateObject("ADSystemInfo")
    $_Object = $_objSysInfo.UserName
    If @ERROR Exit @ERROR EndIf
    $ADSIObjectInfo = $_Object
    Exit 0
   Case $_Object = 'Computer'
    $_objSysInfo = CreateObject("ADSystemInfo")
    $_Object = $_objSysInfo.ComputerName
    If @ERROR Exit @ERROR EndIf
    $ADSIObjectInfo = $_Object
    Exit 0
  EndSelect
 
 
  ; attribute is required if DN is specified 
  ; Exit with error if Attribute is null 
  If VarType($_Attr) < 2
    Exit 87
  EndIf
 
  If VarType($_Attr) = 8
   If Not $_Attr Exit 87 EndIf
  EndIf
 
  If Left($_Object, 7) <> 'LDAP://'
    $_Object = 'LDAP://' + $_Object
  EndIf
 
  ; Get the user pointer 
  $_oObject = GetObject($_Object)
  If @ERROR Exit @ERROR EndIf			; exit if error creating object 
 
  If VarType($_Attr) < 8192
    ; write the value if supplied 
    If $_Value
      $_Cmd = $_D + '_oObject.put("' + $_Attr + '", "' + $_Value + '")'
      $_ = Execute($_Cmd)
      $_oObject.SetInfo
      If @ERROR
        Exit @ERROR
      EndIf
    EndIf
 
    ; read and return the current value 
    $_Cmd = $_D + '_RtnVal = ' + $_D + '_oObject.' + $_Attr
    $_ = Execute($_Cmd)
    $ADSIObjectInfo = $_RtnVal
 
  Else
    $_AValid = 0
    Dim $_RtnVal[UBound($_Attr)]		; prepare to return multiple values	 
    For $_I = 0 to UBound($_Attr)
      If $_Attr[$_I]
        $_AValid = 1
        ; write the value if supplied 
        If $_Value[$_I]
          $_Cmd = $_D + '_oObject.put("' + $_Attr[$_I] + '", "' + $_Value[$_I] + '")'
          $_ = Execute($_Cmd)
          $_oObject.SetInfo
          If @ERROR
            Exit @ERROR
          EndIf
        EndIf
 
       ; read and return the current value 
;KGEN:IgnoreNext 
       $_Cmd = $_D + '_RtnVal[$_I] = ' + $_D + '_oObject.' + $_Attr[$_I]
       $_ = Execute($_Cmd)
 
      EndIf
    Next
    $ADSIObjectInfo = $_RtnVal
    If Not $_AValid Exit 87 EndIf		; no valid values 
  EndIf
 
  Exit @ERROR
 
EndFunction