Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > Security

Security Discussion on securing VB.NET applications, end-user configuration, application activation, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-23-2008, 11:35 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Dec 2007
Posts: 13
Reputation: 30
sebasjuh is on a distinguished programming path ahead
Question Remove user from AD within vb.net?

Hello,

I have a small question!
Is it possible to remove a user from a Active Directory group within Visual Basic 2005?

I'm making a tool to get all the groups and users, so I already have to group name and the username. Now I only want a button to remove the selected user from the selected group but how can I get that?

Can someone help me with this maybe???

Sebas
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-23-2008, 12:47 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 855
Reputation: 499
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

Pretty comprehensive tutorial on Active Directory here.

CodeProject: Working with Active Directory in VB.NET. Free source code and programming help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-24-2008, 6:53 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Dec 2007
Posts: 13
Reputation: 30
sebasjuh is on a distinguished programming path ahead
Default

Thank you MattP for your reply.
I already found that website but when I use that code for deleting a user from a group I got this error:

Quote:
Name 'GetDirectoryObject' is not declared.
I don't know how to fix this....


Edit: This is the code btw:
Code:
Public Shared Sub RemoveUserFromGroup(ByVal UserName As String, _
                  ByVal GroupName As String)

    Dim Domain As New String("")
    
    'get reference to group
    Domain = "/CN=" + GroupName + ",CN=Users," + GetLDAPDomain()
    Dim oGroup As DirectoryEntry = GetDirectoryObject(Domain)
    
    'get reference to user
    Domain = "/CN=" + UserName + ",CN=Users," + GetLDAPDomain()
    Dim oUser As DirectoryEntry = GetDirectoryObject(Domain)
    
    'Add the user to the group via the invoke method
    oGroup.Invoke("Remove", New Object() {oUser.Path.ToString()})
    
    oGroup.Close()
    oUser.Close()
End Sub

Last edited by sebasjuh; 10-24-2008 at 7:43 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-21-2009, 7:32 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Sep 2009
Age: 21
Posts: 1
Reputation: 0
danmrf is on a distinguished programming path ahead
Smile No problem

If you have allready connected to the user using directoryentry, you can get the distinguished name of the user.

dim userdn as string = %userDE%.properties("distinguishedname").value

or by removing the "LDAP://" from the users path.
dim userdn as string = %userDE%.path.remove(0,7)


then you have to open the group using directoryentry

dim groupde as new directoryentry(%your LDAP to the group%)
groupde.properties("member").remove(userdn)
groupde.commitchanges
groupde.close
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On





All times are GMT -4. The time now is 4:13 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.