View Sidebar
Using ADSI to Authenticate Against Active Directory

Using ADSI to Authenticate Against Active Directory

April 25, 2006 11:10 pmComments are Disabled

I dusted off my modest ADSI skills yesterday to help some folks figure out how to authenticate against Active Directory by binding to it using LDAP. Here’s a VBScript version using ADSI (run at command line using cscript.exe).


Dim uid, pwd

WScript.StdOut.Write “User name (with domain prefix): ”
uid = WScript.StdIn.ReadLine

WScript.StdOut.Write “Please enter your password:”
Set objPassword = CreateObject(“ScriptPW.Password”)
pwd = objPassword.GetPassword()

‘ Get just the username (samAccountName)
Dim username
tmp = Split(uid, “\”)
username = tmp(1)

Dim LDAP ‘As IADsOpenDSObject
Dim LDAPString
LDAPString = “LDAP://cn=Users,dc=yourdomain,dc=local”

”’ Important Lines Right Here
Set LDAP = GetObject(“LDAP:”)
Set obj = LDAP.OpenDSObject(LDAPString, uid, pwd, ADS_SECURE_AUTHENTICATION)

For Each o in obj
If o.Class = “user” Then
If o.Get(“samAccountName”) = username Then
WScript.Echo “Found ” & o.Get(“cn”)
End If
End If

Comments are closed