| 订阅 | 在线投稿
分享
 
 
 

修改活动目录用户帐号的密码

来源:互联网网民  宽屏版  评论
2006-11-24 00:50:13

由于经常有人问及此方面的问题所以我将整理出来的代码放到这里,大家参考一下:

使用前请添加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

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
由于经常有人问及此方面的问题所以我将整理出来的代码放到这里,大家参考一下: 使用前请添加COM引用:Active DS Type Library 一下代码在VB[url=http://www.pccode.net].NET[/url]下编译通过 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
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有