Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Help me in making users/deleting users in active directory

Reply
Thread Tools

Help me in making users/deleting users in active directory

 
 
Sara rafiee
Guest
Posts: n/a
 
      10-03-2004


Hi there,
I need help in active directory, I want to make user in it and delete a
user, but I couldn’t. could you please help me.
as follow it is a code which should make user but it gives me error
message. pLease if anyone could correct it and send it to me.
Thanks in advance.

Regards

Sara





Public Sub Makeuser(ByVal DcDNS As String, ByVal username As String,
ByVal newPassword As String)



'Dim DcDNS As String = "bsc.aut.ac.ir" 'DcDNS use this if you
want to supply a server(name)

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



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      10-03-2004
Hi sara:

What is the error message the code generates? What line does it happen
on? Many of the exceptions generated by AD code are security and
permissions related. If you have a permission denied exception, you
may need to run ASP.NET under a domain account instead of a local
machine account.

--
Scott
http://www.OdeToCode.com/

On Sun, 03 Oct 2004 00:40:47 -0700, Sara rafiee <(E-Mail Removed)>
wrote:

>
>
>Hi there,
>I need help in active directory, I want to make user in it and delete a
>user, but I couldn’t. could you please help me.
>as follow it is a code which should make user but it gives me error
>message. pLease if anyone could correct it and send it to me.
>Thanks in advance.
>
>Regards
>
>Sara
>
>
>
>
>
>Public Sub Makeuser(ByVal DcDNS As String, ByVal username As String,
>ByVal newPassword As String)
>
>
>
> 'Dim DcDNS As String = "bsc.aut.ac.ir" 'DcDNS use this if you
>want to supply a server(name)
>
> 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
>
>
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!


 
Reply With Quote
 
 
 
 
Sara rafiee
Guest
Posts: n/a
 
      10-04-2004
Hi,
thanks for your response.
yeah it says access deny, and in line invoke.commitchange
I don't know what should I do, I even used WinNT instead of that but
again this error.
what should I do???



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      10-04-2004
Hi sara:

What you might want to try is impersonating a domain user in
web.config. The domain user should be an account with permissions to
delete an account in active directory.

One way to do this is to add an <indentity> elements in web.config:

<identity impersonate="true" userName ="domain\username"
password="password" />

You can read more about it here:
http://msdn.microsoft.com/library/en...ersonation.asp

--
Scott
http://www.OdeToCode.com/

On Sun, 03 Oct 2004 21:11:00 -0700, Sara rafiee <(E-Mail Removed)>
wrote:

>Hi,
>thanks for your response.
>yeah it says access deny, and in line invoke.commitchange
>I don't know what should I do, I even used WinNT instead of that but
>again this error.
>what should I do???
>
>
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Active X Component can run Power users group but not in users grou Wilmer Hernandez ASP General 4 08-20-2007 08:36 PM
Active Directory users on Cisco PIX Diego Fernández Cisco 3 02-24-2006 09:22 AM
Q: check users in Active Directory =?Utf-8?B?SklNLkgu?= ASP .Net 4 03-21-2005 07:27 PM
Help me in making users/deleting users in active directory Sara rafiee ASP .Net Web Controls 1 10-04-2004 12:00 PM
OT MMC Active Directory Users and Computers Rick MCSE 7 12-24-2003 02:01 PM



Advertisments