Solved

LDAP Query - Password Expires

Posted on 2007-11-30
5
2,744 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

735 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