none
system.directoryservices.accountmanagement RRS feed

  • Question

  • I'm using .NET 4.0 Framework, System.DirectoryServices.AccountManagement as a reference in a simple Windows Application project.    The snippet below shows how I connect to a domain, find a user and check whether their account is locked.   Starting the app, my user is not locked.  On the very first call to the IsAccountLockedOut() method,   the result is false, which is expected.   Without doing anything else, the very NEXT call to the same method returns true.   It's as if the method itself is locking out the user.    I'm running as a user that has full permissions to Active Directory.   Why or how could this happen?

    public void IsLocked()
    {
                principalContext = new PrincipalContext(ContextType.Domain, "foo.local", "OU=FooUsers,DC=foo,DC=local");
                UserPrincipal user = UserPrincipal.FindByIdentity(principalContext, IdentityType.SamAccountName, "fooTester1");
                if (user.IsAccountLockedOut())
                {
                    textBox1.Text = "LOCKED";
                }
                else
                {
                    textBox1.Text = "OK";
    }
            }

    Wednesday, May 21, 2014 2:16 PM

Answers

  • Hello,

    >> It's as if the method itself is locking out the user.

    The method will not lock out the user, it is just to compute the correct store-specific lockout value to determine whether the account is locked out. And with your provided code, I made a test with as below:

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, DomianName);
    
    
                UserPrincipal me = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, IdentityName);
    
    
                if (me.IsAccountLockedOut())
    
                {
    
     
    
                }
    
                else
    
                {
    
     
    
                }

    It always return false whenever I start my app, so I am wondering if the user you are checking  is locked out just right by others before you start it second time.

    You can have a try to check other accounts as using the UserPrincipal.Current:

    UserPrincipal me = UserPrincipal.Current;

    To see whether it will be locked out again when starting the app at second time.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, May 22, 2014 2:50 AM
    Moderator

All replies

  • Hello,

    >> It's as if the method itself is locking out the user.

    The method will not lock out the user, it is just to compute the correct store-specific lockout value to determine whether the account is locked out. And with your provided code, I made a test with as below:

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, DomianName);
    
    
                UserPrincipal me = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, IdentityName);
    
    
                if (me.IsAccountLockedOut())
    
                {
    
     
    
                }
    
                else
    
                {
    
     
    
                }

    It always return false whenever I start my app, so I am wondering if the user you are checking  is locked out just right by others before you start it second time.

    You can have a try to check other accounts as using the UserPrincipal.Current:

    UserPrincipal me = UserPrincipal.Current;

    To see whether it will be locked out again when starting the app at second time.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, May 22, 2014 2:50 AM
    Moderator
  • Hello,

    Any update? I have marked my own reply as answer, if you think it provides no help, please unmark it.

    Thank you for your understanding and support.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 3, 2014 6:27 AM
    Moderator