Why this code don't work ? add user to ad and enable account RRS feed

  • Question

  • HI,  
    Can You tell me, why this code not eneble user account after  added it to AD ?

    this function add user, and close cmd window  with error, but  in AD i can see  just added user account.

    im run  this code  on WS 2k8 ee DC

        public void CreateUserAccount(string connectionPrefix , string userName, string userPassword)
                    DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
                    DirectoryEntry newUser = dirEntry.Children.Add("CN=" + userName, "user");
                    newUser.Properties["samAccountName"].Value = userName;
                    newUser.Invoke("SetPassword", new object[] { userPassword });
                    //enable user account
                    newUser.Properties["userAccountControl"].Value = ~0x200;
                catch (System.DirectoryServices.DirectoryServicesCOMException e)

    Monday, April 27, 2009 10:55 AM

All replies

  • You should put more TRY / CATCH statements between every CommitChanges() so that you can see which part spawns the error
    What Error does it actually produce?
    - Belgian Unified Communications Community : http://www.pro-exchange.be -
    Tuesday, April 28, 2009 11:05 PM
  • HI 
    Have you done it?
    if yes send me the code
    I also want to enable user that i made in OCS
    And hoping for your help as soon as possible

    Thanks in advance

    Sohaib Qazi
    Friday, August 7, 2009 12:45 PM
  • Take a look at this article for some background on manually controlling AD attributes to enable OCS users:
    Jeff Schertz, PointBridge | MVP | MCITP: Enterprise Messaging | MCTS: OCS
    Friday, August 7, 2009 1:12 PM
  • Jeff
    Jeff i want to enable user for OCS that i made just in AD
    For that i need code in C#
    I am not getting help from the code given above or in

    Nothing is helpful for me

    So help me to take out of this

    Thanks in advance

    Sohaib Qazi
    Saturday, August 8, 2009 8:57 AM
  • Hi
    I have done it
    If you needs any help tell me

    Sohaib Qazi
    Monday, August 10, 2009 6:06 AM