Results 1 to 3 of 3

Thread: SetPassword and ChangePassword Invoke

  1. #1
    Join Date
    Jul 2004
    Posts
    153

    SetPassword and ChangePassword Invoke

    I am attempting to set or change a password while the "User must change password at next login" gives me an error for the same thing. I am on a Microsoft AD 2003 environment. I am also using C#, with the following:

    DirectoryEntry DE = new DirectoryEntry
    ("WinNT://domainservername/username,user",username,password,Authenticate.Se cure);
    DE.Invoke("ChangePassword", new object[] {currentpassword, newpassword});
    DE.Close();

    There is something that I am getting COMException on the Invoke. Is there any different way to do it? Thanks.

  2. #2
    Join Date
    Oct 2005
    Posts
    792

    Re: SetPassword and ChangePassword Invoke

    I dont think you will be able to get out of that state programmatically with ADSI using ChangePassword. The issue is that you cannot bind when your password is set to "must change at next logon", so you cant get to the state where you can actually do the change. There is Win Logon that has some special way that it handles this, but basically as far I can tell you, you wont get the same behaviour with ADSI.

  3. #3
    Join Date
    Apr 2011
    Posts
    1

    • object ret = usr.Invoke("SetPassword", userPassword); // is taking around 1.5 minutes to complete...

    Hi All,
    We are able to create new user successfully on the active directory but the SetPassword method is taking around 1.5 minutes to complete the process. Below is the code of the snippet of SetPassword. Is there any better approach to set the password of new user?
    #region SetPassword
    /// <summary>
    /// This function is used to set user password
    /// </summary>
    /// <param name="path"></param>
    /// <param name="userPassword"></param>
    /// <remarks>

    /// </remarks>
    internal static void SetPassword(string path, string userPassword)
    {
    if (_logger.IsDebugEnabled)
    _logger.Debug("ADHelper.cs : Enter SetPassword");

    try
    {
    using (DirectoryEntry usr = GetDirectoryEntry(path))
    {
    object ret = usr.Invoke("SetPassword", userPassword);
    usr.CommitChanges();
    usr.Close();
    }

    if (_logger.IsDebugEnabled)
    _logger.Debug("ADHelper.cs : Exit SetPassword");
    }
    catch (Exception ex)
    {
    if (_logger.IsErrorEnabled)
    _logger.Error("ADHelper.cs : Exception occurred in SetPassword. Message: ", ex);

    throw ex;
    }
    }

    #endregion
    Here is our production environment type.
    • IIS 7
    • ASP.NET 3.5 (C#)
    • Active Directory
    • Windows Server 2008 R2

    Add user snippet
    #region AddUser

    /// <summary>
    /// This function is used to add user to active directory
    /// </summary>
    /// <param name="adPath">Active Directory</param>
    /// <returns>directory entry object</returns>
    /// <remarks>
    /// </remarks>
    public static void AddUser(ADUser adUser)
    {
    if (_logger.IsDebugEnabled)
    _logger.Debug("ADHelper.cs : Enter AddUser");

    // Local variables
    DirectoryEntry oDE = null;
    DirectoryEntry oDENewUser = null;
    DirectoryEntries oDEs = null;

    try
    {
    oDE = GetDirectoryEntry(GetADPath(Constants.EnvironmentType.PROD, adUser.UserType));

    // 1. Create user account
    oDEs = oDE.Children;
    oDENewUser = oDEs.Add(string.Format("{0}=", Constants.ADAttributes.CN) + adUser.UserName, "user");

    // 2. Set properties
    SetProperty(oDENewUser, Constants.ADAttributes.givenName, adUser.FirstName);
    SetProperty(oDENewUser, Constants.ADAttributes.sn, adUser.LastName);
    SetProperty(oDENewUser, Constants.ADAttributes.mail, adUser.Email);
    SetProperty(oDENewUser, Constants.ADAttributes.sAMAccountName, adUser.UserName);
    oDENewUser.CommitChanges();

    // 3. Set password
    SetPassword(oDENewUser.Path, adUser.Password);

    // 4. Enable account
    EnableAccount(oDENewUser);

    oDENewUser.Close();
    oDE.Close();

    if (_logger.IsDebugEnabled)
    _logger.Debug("ADHelper.cs : Exit AddUser");
    }
    catch (Exception ex)
    {
    if (_logger.IsErrorEnabled)
    _logger.Error("ADHelper.cs : Exception occurred in AddUser. Message: ", ex);

    throw ex;
    }
    finally
    {
    if (oDENewUser != null)
    {
    oDENewUser.Dispose();
    oDENewUser = null;
    }

    if (oDEs != null)
    {
    oDEs = null;
    }

    if (oDE != null)
    {
    oDE.Dispose();
    oDE = null;
    }
    }
    }

    #endregion

    THANKS IN ADVANCE!!!

Similar Threads

  1. How do you invoke a procedure from a remote machine ?
    By Fragman in forum Software Development
    Replies: 4
    Last Post: 30-01-2011, 03:29 AM
  2. Invoke servlet from EJB components?
    By Nurhan in forum Software Development
    Replies: 3
    Last Post: 01-04-2009, 09:59 AM
  3. How to invoke servlet filters
    By Pandya in forum Software Development
    Replies: 2
    Last Post: 30-03-2009, 01:31 PM
  4. ASP.NET ChangePassword error using ActiveDirectoryMembershipProvid
    By hindustnidude in forum Active Directory
    Replies: 1
    Last Post: 06-06-2007, 09:05 AM
  5. Replies: 1
    Last Post: 31-03-2007, 08:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,430,073.85370 seconds with 17 queries