Oops,
the oUser.DistinguishedName needs to equal the DN on the user whose last
logon you want to find out.
My bad
Glenn
----- Original Message -----
From: "Glenn Corbett" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 28, 2003 7:14 PM
Subject: Re: [ActiveDir] Last Logon Details
> Rick,
>
> As others have said, the LastLogon porperty isn't replicated between DC's,
> so you have to query each one. I had a similar issue, and use a heavily
> modified version of the code below.
>
> Code below does a variant of what you are after, no warranties expressed
or
> implied. Word wrap will have to be fixed of course
>
> You can use the FormatDateTime function to make the resulting data a bit
> cleaner, ie FormatDateTime(nLast, vbLongDate)
>
> Option Explicit
> Dim oSysInfo, oUser
> Dim oConnection, oCommand, oRoot, sConfig, oResults, sQuery
> Dim nLast, nDate, oDC, oDCUser
>
> Set oConnection = CreateObject("ADODB.Connection")
> Set oCommand = CreateObject("ADODB.Command")
> oConnection.Provider = "ADsDSOObject"
> oConnection.Open "Active Directory Provider"
> Set oCommand.ActiveConnection = oConnection
> Set oRoot = GetObject("LDAP://RootDSE")
> sConfig = oRoot.Get("ConfigurationNamingContext")
> sQuery = "<LDAP://" & sConfig _
> & ">;(ObjectClass=nTDSDSA);AdsPath;subtree"
> oCommand.CommandText = sQuery
> Set oResults = oCommand.Execute
> Do Until oResults.EOF
> Set oDC = _
> GetObject(GetObject(oResults.Fields("AdsPath")).Parent)
> Set oDCUser = GetObject("LDAP://" _
> & oDC.DNSHostName & "/" & oUser.DistinguishedName)
> nDate = oDCUser.LastLogin
> If nDate > nLast Then
> nLast = nDate
> End If
> oResults.MoveNext
> Loop
>
> MsgBox "You last logged into the domain" & vbCrLf & nLast
>
> HTH
>
> Glenn
>
>
> ----- Original Message -----
> From: "Jones, Rick J.(Desktop Engineering)" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, March 28, 2003 10:17 AM
> Subject: RE: [ActiveDir] Last Logon Details
>
>
> Hi;
>
> I am trying to retrieve the last logon account information for a
> specific computer account from Active Directory.
>
> Does anyone have a script to do this?
>
> Or...
>
> If you have another way to determine when the system last logged onto
> the network. This is so we can verify that the account is an active
> entry.
>
> Rick J. Jones
>
> List info : http://www.activedir.org/mail_list.htm
> List FAQ : http://www.activedir.org/list_faq.htm
> List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
>
List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/