Press "Enter" to skip to content

Day: October 4, 2010

VBScript Function to Check Active Directory Domain Access

The following VBScript function can be used to check if a given username and password has access to the specified domain. It will return true or false depending on whether or not access was granted.

function fnCheckAccess(strDomain, strUserID, strUserPWD)
 
    const ADS_SECURE_AUTHENTICATION = &H01
    const ADS_CHASE_REFERRALS_ALWAYS = &H60
 
    dim objDSO
    dim objUser
    dim strPath
 
    strPath = "LDAP://" & strDomain
 
    On Error Resume Next
    set objDSO = GetObject("LDAP:")
    set objUser = objDSO.OpenDSObject(strPath, strUserID, strUserPWD, ADS_SECURE_AUTHENTICATION OR ADS_CHASE_REFERRALS_ALWAYS)
    if Err.Number <> 0 then
        fnCheckAccess = False
    else
        fnCheckAccess = True
    end if
    Err.Clear
    On Error Goto 0
 
    set objDSO = Nothing
    set objUser = Nothing
 
end function

Leave a Comment