create users/deleting users in active directory
Hi there,
I have problem in making user in active directory, could anyone help me, my code is as follow, if I use WINNT I will recieve the error that "access deny" in line invoke.commitechanges , if I use LDAP , it gives me another kind of exception in this line rootDN = DirectCast(ad.Properties("defaultNamingContext").V alue, String could anyone please help me. thanks in advance.
Public Sub Makeuser(ByVal DcDNS As String, ByVal username As String, ByVal newPassword As String)
Dim rootDN As String
Dim ad As DirectoryEntry
ad = New DirectoryEntry(String.Format("LDAP://{0}/ad", DcDNS), "myadminaccount", "myadmin password", AuthenticationTypes.Secure Or AuthenticationTypes.Sealing)
rootDN = DirectCast(ad.Properties("defaultNamingContext").V alue, String)
Dim NewUser As DirectoryEntry = ad.Children.Add(username, "user")
NewUser.Invoke("SetPassword", New Object() {newPassword})
NewUser.Invoke("Put", New Object() {"Description", "Test User from .NET"})
NewUser.CommitChanges()
NewUser.Close()
Dim grp As DirectoryEntry
grp = ad.Children.Find("Guests", "group")
If grp.Name <> "" Then
grp.Invoke("Add", New Object() {NewUser.Path.ToString()})
End If
End Sub
Regards
Sara
__________________
Regards
Sara
|