Active Directory密码更改 - 不会搜索上下文

时间:2012-09-25 14:34:13

标签: asp-classic vb6

我有一个遗留脚本,可以为我们的学生帐户处理一些密码重置,但是当用户转移到Sub OU并导致问题时,它似乎遇到了一些麻烦。

基本上以下是LDAP连接字符串。

strLDAP ="LDAP://Studc01.student.college.ad:389/OU=Students,DC=student,DC=college,DC=ad"

如果学生帐户位于此主OU中,则脚本似乎可以将其密码重置为指定的默认值。但是,如果帐户位于顶级学生OU的子OU中,则脚本会失效并失败。

该脚本如下所示,并从先前输入的文本字段中获取一些信息。

if request.form("AccountName")<> "" then
sAMAccountName = request.form("AccountName")
cUser = request.form("User")
else
response.write("There was an error no account details were given.")
response.end
End if

strLDAP ="LDAP://Studc01.student.college.ad:389/OU=Students,DC=student,DC=college,DC=ad"

Set obj = GetObject(strLDAP)

for each objUser in obj
if ucase(objUser.sAMAccountName) = ucase(sAMAccountName) then
Exit for
end if
next

Response.write("The password has now been reset (Password1) for account " &   objUser.sAMAccountName & ", thank you")

objUser.SetPassword "Password1"
objUser.Put "pwdLastSet", 0
objUser.SetInfo

脚本似乎使用IIS中的应用程序池中的网络服务来运行 - 有关它无法搜索上下文的原因的任何想法?

1 个答案:

答案 0 :(得分:0)

使用For Each的循环用户效率非常低。尝试使用ADO的ADsDSOObject OLEDB提供程序来查询像此

的AD子树
strLDAP = "LDAP://" & GetObject("LDAP://RootDSE").Get("defaultNamingContext")
sAMAccountName = "wqw"

With CreateObject("ADODB.Connection")
    .Open "Provider=ADsDSOObject;Page Size=1000;Searchscope=2"
    With .Execute("<" & strLDAP & ">;(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & sAMAccountName & "));ADsPath;subtree")
        If Not .EOF Then
            Set objUser = GetObject(.Fields("ADsPath").Value)
            WScript.echo "Will reset password of " & objUser.name
        End If
    End With
End With

另请注意,您必须使用(&(objectCategory=person)(objectClass=user))过滤域用户,否则可能会有重置计算机帐户密码的风险。