locked
Adding a User to a group. RRS feed

  • Question

  • User-1668286398 posted

    Heyya,

          How to add a user to a group in AD?? The following code does not work. Any help would be appreciated.

            Dim gr As DirectoryEntry = New DirectoryEntry("LDAP://cn=group,ou=User,dc=auto,dc=com")
            Dim ne As DirectoryEntry = New DirectoryEntry
    (LDAP://cn=username,ou=User,dc=auto,dc=com)
            gr.Properties("member").Add(ne)
            gr.CommitChanges()

    An unspecified error occurs. What could be the cause of this error? What is the solution?

    Cheers,

    Saurabh

    Monday, February 27, 2006 5:20 AM

All replies

  • User1354132231 posted
    The .Add() method is looking to add to that attribute.  That attribute is DN-syntax if you check the schema.  This indicates that you should be putting a DN-string into that Add() method, not an object like a DirectoryEntry.

    It is looking for "CN=Username,OU=user,DC=blah"

    Monday, February 27, 2006 1:04 PM
  • User-1668286398 posted

    Yeah its a kinda obvious mistake. But after I changed it, it gives me another error. Something like

    The server is unwilling to process your request.

    The same program is able to create and delete users. I have granted NETWORK SERVICE complete control over the AD. So I do not think it is a problem with the permissions. What could be the cause of this error? 

    Monday, March 6, 2006 1:46 AM
  • User1354132231 posted
    NETWORK SERVICE is a local account, not a domain account unless you have installed IIS on your domain controllers (bad!).  I suspect that is what you have now.

    Make sure you are using exactly "CN=foo,OU=blah,DC=yeah" format (notice there is no LDAP://) when using the Add method.
    Wednesday, March 8, 2006 11:47 AM