locked
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)
            {
                try
                {
                    DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
                    DirectoryEntry newUser = dirEntry.Children.Add("CN=" + userName, "user");
                    newUser.Properties["samAccountName"].Value = userName;
                    newUser.CommitChanges();
                    newUser.Invoke("SetPassword", new object[] { userPassword });
                    newUser.CommitChanges();                        
                    //enable user account
                    newUser.Properties["userAccountControl"].Value = ~0x200;
                    newUser.CommitChanges();               
                    newUser.Close();
                    dirEntry.Close();
                 
                }
                catch (System.DirectoryServices.DirectoryServicesCOMException e)
                {
                    Console.WriteLine("{}",e);
                    Console.ReadLine();
                }
                      
            }


    #cheers!
    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

    Regards
    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:
    http://blogs.pointbridge.com/Blogs/schertz_jeff/Pages/Post.aspx?_ID=29
    Jeff Schertz, PointBridge | MVP | MCITP: Enterprise Messaging | MCTS: OCS
    Friday, August 7, 2009 1:12 PM
    Moderator
  • 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

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

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