Results 1 to 7 of 7

Thread: [RESOLVED] [2008] pwdLastSet and AD

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Resolved [RESOLVED] [2008] pwdLastSet and AD

    Hi All

    So i am using the below which work perfectly i now need to get the pwdLastSet for the user.

    How would i go about this?

    Thanks



    Code:
    Module ad_lookup
    
        ' Public variabled used across the whole application
        Public strcn As String
        Public strtele As String
        Public strtitle As String
        Public strdepartment As String
        Public strtelephone As String
        Public strcompany As String
        Public strmail As String
        Public strmobile As String
        Public strsn As String
        Public strgivenname As String
        Public strl As String
        Public strhome As String
        Public strpwddate As Date
    
        ' struser gets the username so it can be used in the AD lookup script
        Public struser As String = System.Environment.UserName
    
        ' Function to connect to AD 
        Public Function GetDirectoryEntry() As DirectoryServices.DirectoryEntry
            Dim de As DirectoryServices.DirectoryEntry = New DirectoryServices.DirectoryEntry()
            de.Path = "LDAP://DC=xxx,DC=com"
            Return de
        End Function
    
    
    
        Public Sub get_user_info(ByVal userid As String)
    
            Dim ds As New DirectoryServices.DirectorySearcher(GetDirectoryEntry)
            ds.Filter = "((samaccountname=" & struser & "))"
            Dim results As System.DirectoryServices.SearchResultCollection = ds.FindAll()
            For Each result As System.DirectoryServices.SearchResult In results
                strcn = (result.Properties("cn")(0).ToString())
                strtitle = (result.Properties("title")(0).ToString)
                strdepartment = (result.Properties("department")(0).ToString)
                strcompany = (result.Properties("company")(0).ToString)
                If Not IsNothing(result.Properties("mail")(0).ToString) Then
                    strmail = (result.Properties("mail")(0).ToString)
                Else
                    strmail = ""
                End If
                If Not IsNothing(result.Properties("TelephoneNumber")(0).ToString) Then
                    strtelephone = (result.Properties("TelephoneNumber")(0).ToString)
                Else
                    strtelephone = ""
                End If
                If Not IsNothing(result.Properties("mobile")(0).ToString) Then
                    strmobile = (result.Properties("mobile")(0).ToString)
                Else
                    strmobile = ""
                End If
                strsn = (result.Properties("sn")(0).ToString)
                strgivenname = (result.Properties("GivenName")(0).ToString)
                strl = (result.Properties("l")(0).ToString)
                If Not IsNothing(result.Properties("HomeDirectory")(0).ToString) Then
                    strhome = ""
                Else
                    strhome = (result.Properties("HomeDirectory")(0).ToString)
                End If
            Next
        End Sub
    
    End Module

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2008] pwdLastSet and AD

    Did you actually try to resolve this yourself at all? I mean, I'm assuming you have just copied and pasted that code you posted from someone else because if you wrote it yourself then you would realise that you get the PwdLastSet attribute in the exact same way that you have got those other attributes.
    E.g:
    vb.net Code:
    1. (result.Properties("PwdLastSet")(0))
    However, you will notice that this just brings back a really long number... so you are going to have to play around a little and do some research to find out how to convert that to something a little more useable. A good place to start would be the MSDN documentation as you will see that it explains what that really long number actually is: http://msdn.microsoft.com/en-us/libr...30(VS.85).aspx
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: [2008] pwdLastSet and AD

    this is what i used and its working fine.
    Code:
     Dim strpasslast As Long = (result.Properties("PwdLastSet")(0))
    
                Dim datelastset As Date = Date.FromFileTimeUtc(strpasslast)

  4. #4

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: [RESOLVED] [2008] pwdLastSet and AD

    Just when i thought all was good i have now discovered that this will only work if you are an administrator in AD not a normal user.. Any ideas?

  5. #5
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] [2008] pwdLastSet and AD

    Well of course it wont work if you are a normal user... would you really want to have all of your users able to view AD properties for every other user in your domain?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: [RESOLVED] [2008] pwdLastSet and AD

    i am only looking at their details....


    I call module using
    Code:
     get_user_info(struser)
    where struser is the user id

    it works fine for all the other properties just not pwdlastset

  7. #7

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    Re: [RESOLVED] [2008] pwdLastSet and AD

    any ideas on why this would not work?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width