Solved

LDAP Query - Password Expires

Posted on 2007-11-30
5
2,739 Views
Last Modified: 2011-09-20
Can you tell me why these dont work?

        private TimeSpan GetMaxPasswordAge()
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://SERVER1:3268");
            entry.AuthenticationType = AuthenticationTypes.Secure;

            DirectorySearcher searcher = new DirectorySearcher(entry, "(objectClass=*)", null, SearchScope.Base);
            SearchResult result = searcher.FindOne();
            TimeSpan maxPwdAge = TimeSpan.MinValue;
            if (result.Properties.Contains("maxPwdAge"))
                maxPwdAge = TimeSpan.FromTicks((long)result.Properties["maxPwdAge"][0]);
           
            return maxPwdAge.Duration();
        }

//-------------------
                    searcher = new DirectorySearcher(entry, filter, new string[] { "maxpwdage" });
                    result = searcher.FindOne();
                    if (result.Properties["pwdLastSet"].Count > 0)
                    {
                        if (result.Properties["pwdLastSet"][0].ToString() != "")
                            pwdLastSet = result.Properties["pwdLastSet"][0].ToString().ToLower();
                    }
0
Comment
Question by:Rowdyone52
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20383077
are you getting an exception now? what problems are u having?
0
 

Author Comment

by:Rowdyone52
ID: 20383097
The value for result.Properties["maxPwdAge"].Count  and  result.Properties["pwdLastSet"].Count  are always zero.  I dont get an exception.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20383136
List out all the properties and see if this property exists in the Search Result properties.
It may not be available or u might have been using the wrong property name
ResultPropertyCollection myResultPropColl;

myResultPropColl = mySearchResult.Properties;

Console.WriteLine("The properties of the " + 

                  "'mySearchResult' are :");

foreach( string myKey in myResultPropColl.PropertyNames)

{

   string tab = "    ";

   Console.WriteLine(myKey + " = ");

   foreach( Object myCollection in myResultPropColl[myKey])

   {

      Console.WriteLine(tab + myCollection);

   }

}

Open in new window

0
 

Author Comment

by:Rowdyone52
ID: 20383669
it isnt available, but I am looking all over the net and it should be.  I cannot figure out why I can't access that property name.
0
 
LVL 21

Accepted Solution

by:
surajguptha earned 500 total points
ID: 20383701
I dont know if this would help you but posting it anyways
http://msdn2.microsoft.com/en-us/library/ms974598.aspx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now