Page 1 of 1 1
Topic Options
#15247 - 2001-12-16 05:59 AM Last logon date
Anonymous
Unregistered


Hi all,

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

thanks in advance.

Top
#15248 - 2001-12-16 05:26 PM Re: Last logon date
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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?

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#15249 - 2001-12-16 07:39 PM Re: Last logon date
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#15250 - 2001-12-16 09:07 PM Re: Last logon date
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#15251 - 2001-12-16 09:31 PM Re: Last logon date
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Les,

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

Oh well.

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#15252 - 2001-12-17 01:33 AM Re: Last logon date
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#15253 - 2001-12-17 03:40 PM Re: Last logon date
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Les,

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

Thanks again,

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.056 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org