Click here to Skip to main content
Licence 
First Posted 4 Jul 2007
Views 11,500
Downloads 93
Bookmarked 13 times

Creating Active Directoy group OwnerShip using c#

By | 4 Jul 2007 | Article
Creating Active Directoy group OwnerShip using c#

Introduction

The code given below will set the group owner of a group in Active Directory.

Background

To create the OwnerShip of a group in Active Directory you just need to call the Invoke function of the DirectoryEntry object for group. i.e.

dEntry.Invoke("Put", new object[] { "managedBy", "LDAP://CN=ravi.kant,DC=ADS,DC=COM"});

Using the code

A brief desciption of how to use the article or code. The class names, the methods and properties, any tricks or tips.

Blocks of code should be set as style "Formatted" like this:

//
// Any source code blocks look like this
   public bool SetOwnerOfGroup(string ownerName, string groupLdapPath)
        {
            bool blSetGroup = false;
            try
            {
                DirectoryEntry dEntryUser = new DirectoryEntry(LdapUtility.GetCongifValue("LDAPPath"));
                DirectorySearcher dSearch = new DirectorySearcher(dEntryUser);
                dSearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
                string filter = "(&(objectCategory=user)(samaccountname=" + ownerName + 
"))";
                dSearch.Filter = filter;
                SearchResult sr = dSearch.FindOne();
                if (sr != null)
                {
                    DirectoryEntry dEntryUserObj = sr.GetDirectoryEntry();
                    using (dEntryUserObj)
                    {
                        DirectoryEntry dEntry = new DirectoryEntry(groupLdapPath);
                        string path = dEntryUserObj.Path.Replace("LDAP://", "");
                        dEntry.Invoke("Put", new object[] { "managedBy", path });
                        //dEntry.InvokeSet("managedBy", dEntryUserObj);
                        dEntry.CommitChanges();
                        blSetGroup = true;
                    }
                }
            }
            catch (Exception ex)
            {
          throw ex;
            }
            return blSetGroup;
        }

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ravi Kant Kumar

Software Developer (Senior)

United States United States

Member

He is working as a software engineer from last 6 years. His domain of expertise is security, network and business. He is working in .net technology and prior to that worked in c and c++.
 
His educational background is very sound. He has done BITM, MCA then CEPPM from IIT New Delhi and GMPIT from IIM Calcutta.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionConstraint violation error. Pinmemberanil_nk12:28 14 May '08  
GeneralPolish a bit PinmemberHannes Foulds23:17 4 Jul '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 5 Jul 2007
Article Copyright 2007 by Ravi Kant Kumar
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid