As the thread title indicates I needed to use Active Directory to validate a user name.
I wrote a quick & dirty function that is working for me ...
(defun _UserExists ( domain user / conn cmd rs result )
;; Translated from:
;;
;; http://gallery.technet.microsoft.com/scriptcenter/13e06435-c105-48d4-9128-29303b1d36f5.
;;
;; Note: Substituted <LDAP://domain.local> for <LDAP://dc=fabrikam,dc=com>
;;
;; Original sample VBScript Code from web ^ page:
;;
;; strUserName = "kenmyer"
;; dtStart = TimeValue(Now())
;; Set objConnection = CreateObject("ADODB.Connection")
;; objConnection.Open "Provider=ADsDSOObject;"
;;
;; Set objCommand = CreateObject("ADODB.Command")
;; objCommand.ActiveConnection = objConnection
;;
;; objCommand.CommandText = _
;; "<LDAP://dc=fabrikam,dc=com>;(&(objectCategory=User)" & _
;; "(samAccountName=" & strUserName & "));samAccountName;subtree"
;;
;; Set objRecordSet = objCommand.Execute
;;
;; If objRecordset.RecordCount = 0 Then
;; WScript.Echo "sAMAccountName: " & strUserName & " does not exist."
;; Else
;; WScript.Echo strUserName & " exists."
;; End If
;;
;; objConnection.Close
;;
;; Examples:
;;
;; (_UserExists "mydomain" "eclapton") >> T
;; (_UserExists "mydomain" "bogus") >> nil
(setq
conn (vlax-create-object "ADODB.Connection")
cmd (vlax-create-object "ADODB.Command")
)
(vlax-invoke conn 'Open "Provider=ADsDSOObject;")
(vlax-put cmd 'ActiveConnection conn)
(vlax-put cmd 'CommandText
(strcat
"<LDAP://" domain ".local>;(&(objectCategory=User)"
"(samAccountName=" user "));samAccountName;subtree"
)
)
(setq result
(and
(setq rs (vl-catch-all-apply 'vlax-invoke (list cmd 'Execute)))
(eq 'vla-object (type rs))
(< 0 (vlax-get rs 'RecordCount))
)
)
(vl-catch-all-apply 'vlax-invoke (list conn 'Close))
(vl-catch-all-apply 'vlax-release-object (list rs))
(vl-catch-all-apply 'vlax-release-object (list cmd))
(vl-catch-all-apply 'vlax-release-object (list conn))
result
)
For what it's worth .... cheers.
Edit: Tightened up the code slightly because I'm helplessly retentive.