**DONOTDELETE**
(Lurker)
2001-12-16 05:59 AM
Last logon date

Hi all,

Is there a way to find out the last time a user logged off using kix script?

thanks in advance.

Les
(KiX Master)
2001-12-16 05:26 PM
Re: Last logon date

willo,
I rely on my trusty Hyena to give me this info. Hyena however, will not do it programmatically from KiX. I believe ADSI would be able to give you that. Unfortunately, I know less about ADSI than men know about women.

I gleaned this tidbit from the Microsoft Active Directory SDK:

quote:

lastLogoff (Non-replicated)
The lastLogoff property specifies when the last logoff occurred. This value is stored as a large integer that represents the number of seconds elapsed since 00:00:00, January 1, 1970. This property is maintained separately on each domain controller in the domain. A value of zero means that the last logoff time is unknown. To get an accurate value for the user's last logoff in the domain, each domain controller in the domain must be queried and the largest value should be used.

It is also referenced in the IADsUser properties and methods section as "LastLogoff".

Where's our resident ADSI guru when we need him?

Kdyer
(KiX Supporter)
2001-12-16 07:39 PM
Re: Last logon date

Willo/Les,

Here you go (untested).

Ref - IADsUser Property Methods

Last log off

code:

Dim $usr As IADsUser
$usr = GetObject("WinNT://"+@LDOMAIN+"/"@USERID+",user")
$lastlogof = $usr.LastLogoff

Last log in

code:

Dim $usr As IADsUser
$usr = GetObject("WinNT://"+@LDOMAIN+"/"@USERID+",user")
$lastlogon = $usr.LastLogin


HTH,

- Kent

Les
(KiX Master)
2001-12-16 09:07 PM
Re: Last logon date

Thanks Kent,

Close... real close...

I'm not familiar with the "As IADsUser" parameter on the DIM statement, and neither is KiX.

Missing a "+" on "@USERID+",. Should read "+@USERID+". So, borrowing from your code:

code:

break on
Dim $usr
$usr = GetObject("WinNT://bdc/administrator,user")
$lastlogof = $usr.LastLogoff
$lastlogin = $usr.LastLogin

? "Last logoff according to bdc = "+$lastlogof
? "Last logon according to bdc = "+$lastlogin

$usr = GetObject("WinNT://pdc/administrator,user")
$lastlogof = $usr.LastLogoff
$lastlogin = $usr.LastLogin

? "Last logoff according to pdc = "+$lastlogof
? "Last logon according to pdc = "+$lastlogin
get $_


The output:

quote:

Last logoff according to bdc = 12/12/2001 7:42:52 AM
Last logon according to bdc = 12/14/2001 3:56:20 PM
Last logoff according to pdc = 12/16/2001 4:36:08 AM
Last logon according to pdc = 12/16/2001 4:36:06 AM

Hmm, 4:36 AM??? Must of set administrator for a service account! OOPS!

As you can see from the example above, the values are not replicated and must be read from all DCs.

Kdyer
(KiX Supporter)
2001-12-16 09:31 PM
Re: Last logon date

Les,

Like I said.. I just threw that together.. I knew it needed some debugging..

Oh well.

- Kent

Les
(KiX Master)
2001-12-17 01:33 AM
Re: Last logon date

Kent,
No prob...
I only mentioned it for those cut and paste junkies looking for a quick fix. Many may not take the time to figure it out on their own.

Willo,
Is this what you were looking for? Were you wanting to use this in an admin or logon script? If you run it on anything other that Win2K/XP, you'll need the ADSI provider installed.

Kdyer
(KiX Supporter)
2001-12-17 03:40 PM
Re: Last logon date

Les,

Thanks for the help on this.. I have posted a new function and have credited you for the assist.

Thanks again,

- Kent