首先需要添加对System.DirectoryServices名域空间的引用,定位到"项目->添加引用
->.NET->System.DirectoryServices.dll",添加上即可.下面是代码部分:
Dim MyString As String = "WinNT://" + System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace("\", "/")
'System.Security.Principal.WindowsIdentity.GetCurrent().Name得到的是机器当前的用户名,比如:MyComputerName\Administrator
Dim MyDirectoryEntry As New DirectoryEntry(MyString)
MyDirectoryEntry.Invoke("setPassword", "newpassword")
'将当前用户的密码修改为"newPassword"
MyDirectoryEntry.CommitChanges()