I fixed it myself and wrote how. And yes, it's tested.
The main problem is in the func _AD_ObjectExists.
; #FUNCTION# ====================================================================================================================
; Name...........: _AD_ObjectExists
; Description ...: Returns 1 if exactly one object exists for the given property in the local Active Directory Tree.
; Syntax.........: _AD_ObjectExists([$sObject = @UserName[, $sProperty = ""]])
; Parameters ....: $sObject - [optional] Object (user, computer, group, OU) to check (default = @UserName)
; $sProperty - [optional] Property to check. If omitted the function tries to determine whether to use sAMAccountname or FQDN
; Return values .: Success - 1, Exactly one object exists for the given property in the local Active Directory Tree
; Failure - 0, sets @error to:
; |1 - No object found for the specified property
; |x - More than one object found for the specified property. x is the number of objects found
; Author ........: Jonathan Clelland
; Modified.......: water
; Remarks .......: Checking on a computer account requires a "$" (dollar) appended to the sAMAccountName.
; To check the existence of an OU use the FQDN of the OU as first parameter because an OU has no SamAccountName.
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _AD_ObjectExists($sObject = @UserName, $sProperty = "")
If $sObject = Default Then $sObject = @UserName
If $sProperty = "" Or $sProperty = Default Then
$sProperty = "samAccountName"
If StringMid($sObject, 3, 1) = "=" Then $sProperty = "distinguishedName"
EndIf
If IsObj($__oAD_Command) Then
$__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sAD_DNSDomain & ">;(" & $sProperty & "=" & $sObject & ");ADsPath;subtree"
Local $oRecordSet = $__oAD_Command.Execute ; Retrieve the ADsPath for the object, if it exists
If IsObj($oRecordSet) Then
If $oRecordSet.RecordCount = 1 Then
Return 1
ElseIf $oRecordSet.RecordCount > 1 Then
Return SetError($oRecordSet.RecordCount, 0, 0)
Else
Return SetError(1, 0, 0)
EndIf
Else
Return SetError(1, 0, 0)
EndIf
Else
Return SetError(1, 0, 0)
EndIf
EndFunc ;==>_AD_ObjectExists
+ The solution _AD_Close() see above.