Reset user password in domain by VB script - TechRepublic
Question
July 28, 2008 at 09:20 AM
anirudh.gupta

Reset user password in domain by VB script

by anirudh.gupta . Updated 18 years ago

hi i am having my domain environment but too easier my process i need to delegate some task to my other engineers in my team . but i am facing problem while creating vb script for this . i have already delegated the rights on my domain . still its not having success on it .
username=inputbox(“Enter username:”)
if username = “” then wscript.Quit
strNewPassword = “Passw0rd”
ldapPath = FindUser(username)

if ldapPath = “Not Found” then
wscript.echo “User not found!”
Else
‘ Set password
objUser.SetPassword strNewPassword
‘objUser.SetInfo ‘ Save Changes
‘If Choice = username Then
‘ objUser.SetPassword (strNewPassword)
‘SetPassword = strNewPassword
‘ Display message if error changing password
If Err.Number <> 0 Then
Wscript.Echo “Unable to change password for user: ” & _
objUser.sAMAccountName
Err.Clear
else
‘ Keep count of the number of password changes
intPasswordChanges = intPasswordChanges + 1
End If
end If

‘End if

Function FindUser(Byval UserName)
on error resume next

set objRoot = getobject(“LDAP://RootDSE”)
domainName = objRoot.get(“defaultNamingContext”)
set cn = createobject(“ADODB.Connection”)
set cmd = createobject(“ADODB.Command”)
set rs = createobject(“ADODB.Recordset”)

cn.open “Provider=ADsDSOObject;”

cmd.activeconnection=cn
cmd.commandtext=”SELECT ADsPath FROM ‘LDAP://” & domainName & _
“‘ WHERE sAMAccountName = ‘” & UserName & “‘”

set rs = cmd.execute

if err<>0 then
wscript.echo “Error connecting to Active Directory Database:” & err.description
wscript.quit
else
if not rs.BOF and not rs.EOF then
rs.MoveFirst
FindUser = rs(0)
else
FindUser = “Not Found”
end if
end if
cn.close
end function

‘ Display message
wscript.echo “Finished” & vbcrlf & intPasswordChanges & _
” Passwords changed”

please anybody help in this regard

This discussion is locked

All Comments