Getting the PwdLastSet from ADSI

Discussion in 'ASP .Net' started by Kenneth Keeley, Aug 3, 2004.

  1. Hi,

    I am looking for a sample of how to get the password last set for a user in
    active directory in a format that we can read. I am using ASP.Net and C# I
    have got as far as get the value. but I would like it as a normal date time
    value. or at least display it as a string. if I use the code below the
    response I get is "The password was last set :System.__ComObject" How do I
    get this to a norma date format.

    Thanks
    Kenneth Keeley

    // Create Active Directory Object.
    DirectoryEntry AdsiEntry = new DirectoryEntry(_Path, _Domain + @"\" +
    _AdminUserName, _AdminPassword);

    // Create an Active Directory Search.
    DirectorySearcher AdsiSearch = new DirectorySearcher(AdsiEntry);

    // Find UserName in Active Directory.
    AdsiSearch.Filter = "(SAMAccountName=" + UserName + ")";
    SearchResult Result = AdsiSearch.FindOne();

    // Get the users directory Entry.
    DirectoryEntry UserEntry = Result.GetDirectoryEntry();

    // Grab the "pwdLastSet" property.
    pwdLastSetVal = UserEntry.Properties["pwdLastSet"].Value;

    MyOutPut.Value = "The password was last set :" + pwdLastSetVal + "<br>";
     
    Kenneth Keeley, Aug 3, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin Rich

    ADSI - Syntax for msExchTurfListNames

    Justin Rich, Jun 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    968
    Justin Rich
    Jun 26, 2003
  2. khaja shaik

    ADSI/LDAP Query

    khaja shaik, Jul 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    626
    khaja shaik
    Jul 21, 2003
  3. Roy Osherove

    Access Denied for WMI/ADSI over ASP.Net

    Roy Osherove, Sep 9, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    7,227
    s.becker
    Sep 14, 2003
  4. venkat

    Retrieve logon user name from ADSI

    venkat, Nov 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    468
    venkat
    Nov 6, 2003
  5. Michael P. Nugent

    Getting sub-objects from ADSI

    Michael P. Nugent, Jul 23, 2003, in forum: Python
    Replies:
    0
    Views:
    378
    Michael P. Nugent
    Jul 23, 2003
Loading...

Share This Page