Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Windows Server系統教程 >> Windows Server教程 >> 修改活動目錄用戶帳號地口令

修改活動目錄用戶帳號地口令

日期:2017/1/24 11:02:22      編輯:Windows Server教程


由於經常有人問及此方面的問題所以我將整理出來的代碼放到這裡,大家參考一下:
使用前請添加COM引用:Active DS Type Library
一下代碼在VB.NET下編譯通過
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('更改用戶密碼時發生錯誤( " & 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教程網 All Rights Reserved