Modify the password of the Active Directory user account

  

Since I am often asked this question, I will put the compiled code here, you can refer to it:
Please add a COM reference before use: Active DS Type Library
The code is in VB.NET Compile under
Function DomainPassword() As String
Dim info As New ActiveDs.ADSystemInfoClass()
Dim retDomain As String
retDomain = havedomainname(info.DomainDNSName)
Dim OUname As String = "Users"
Call getuser(retDomain, "Administrator", OUname, " ", " ")
End Function
Private Sub getuser(ByVal strDomain As String, ByVal strUser As String, ByVal organizationname As String, ByVal oldPasswd As String, ByVal newPasswd As String)
Dim user As ActiveDs.IADsUser
Try
user = GetObject( "LDAP://CN= " & strUser & ", " & organizationname & ; ", " & strDomain)
user.ChangePassword(oldPasswd, newPasswd)
Catch ex As Exception
Response.Write( " <script >alert('Change User Secret An error occurred ( " & ex.Source & "): " & ex.Message & "') </script > ")
Response.End()
End Try
End Sub
Function havedomainname(ByVal strdomainName As String)
Dim a(), b, d As String, i, e As Integer
a = Split(strdomainName, ". ", -1, 1)
e = UBound(a)
For i = 0 To e
If i < > e Then
b = a(i)
d = d & "DC= " & a(i) & ", "
Else
d = d & "DC= " & a(i)
End If
Next
havedomainname = d
End Function



Copyright © Windows knowledge All Rights Reserved