[gptalk] Re: Xp display last login time

  • From: "Nelson, Jamie R" <Jamie.Nelson@xxxxxxxxxxxxxxxxxxx>
  • To: <gptalk@xxxxxxxxxxxxx>
  • Date: Thu, 27 Mar 2008 10:37:39 -0500

The attached script will show the interactive user's logon information for the 
system the script is executed on. If wanting the lastLogon LDAP attribute for 
the domain you can bind to the user object and convert the Integer8 date value, 
but if you have multiple DCs, you really need to check each one to get exact 
information. Or you can look at the replicated lastLogonTimestamp attribute 
(Windows 2003 and up), which is replicated every 7-14 days.

Jamie Nelson | Systems Engineer | Systems Support, Information Technology | I N 
T E G R I S Health | Phone 405.552.0903 | Fax 405.553.5687 | 
http://www.integrisok.com

-----Original Message-----
From: gptalk-bounce@xxxxxxxxxxxxx [mailto:gptalk-bounce@xxxxxxxxxxxxx] On 
Behalf Of Darren Mar-Elia
Sent: Thursday, March 27, 2008 10:14 AM
To: gptalk@xxxxxxxxxxxxx
Subject: [gptalk] Re: Xp display last login time

There is nothing native to GP to do that. You would have to write some kind of 
app that runs, probably in a logon script or as part of a startup group, that 
grabs that info. Also, you have to differentiate btw. Last logon to AD or last 
logon to that workstation.

Darren

-----Original Message-----
From: gptalk-bounce@xxxxxxxxxxxxx [mailto:gptalk-bounce@xxxxxxxxxxxxx] On 
Behalf Of sunshine.baines@xxxxxxxxx
Sent: Thursday, March 27, 2008 6:58 AM
To: gptalk@xxxxxxxxxxxxx
Subject: [gptalk] Xp display last login time

Does anyone know how to display the last login time when a user logins to an XP 
PC on a domain.  I want this to be a pop up that users will see when they login.
Sent from my BlackBerry® wireless device from U.S. Cellularb‹j{²ær¸yúš
jYÊÇv)zf–Ú¦Ö’·¹ë~·–+²ŠÂ+º{nlj·žØJæyˉé9–ˆŠxžÚ…çyé²Û®n)z·qàrzǮؖ+j·½¨i¹jضŸÃ
­çŠË¢¸j·Š÷þ
jY

***********************
You can unsubscribe from gptalk by sending email to 
gptalk-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field OR by 
logging into the freelists.org Web interface. Archives for the list are 
available at http://www.freelists.org/archives/gptalk/
************************


This e-mail may contain identifiable health information that is subject to 
protection under state and federal law. This information is intended to be for 
the use of the individual named above. If you are not the intended recipient, 
be aware that any disclosure, copying, distribution or use of the contents of 
this information is prohibited and may be punishable by law. If you have 
received this electronic transmission in error, please notify us immediately by 
electronic mail (reply).
'///////////////////////////////////////////////////////////////
'Name: LogonInfo.vbs
'Author: Jamie Nelson
'Version: 1.0
'Purpose: Get logon session information for current user.
'-----------Date--------Version-----ChangeLog-------------------
'History:       8/6/2007        1.0                     Initial code developed.
'///////////////////////////////////////////////////////////////

'Option Explicit
On Error Resume Next

'===============================================================
'Declare variables, instantiate common script objects
'===============================================================

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim wsh : Set wsh = CreateObject("WScript.Shell")
Dim wsn : Set wsn = CreateObject("WScript.Network")
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

'===============================================================
'Begin Execution of Script
'===============================================================

Dim objWMI, colLogonSessions, colSessionProcesses
Set objWMI = 
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Dim strSessionId, dtmSessionStart, intLogonType

Dim strDomain : strDomain = wsn.UserDomain
Dim strUser : strUser = wsn.UserName

'// Get session id's for current user (can be multiple ones)
Set colLogonSessions = objWMI.ExecQuery("ASSOCIATORS OF " & _
        "{Win32_Account.Domain=""" & strDomain & """,Name=""" & strUser & """} 
" & _
        "WHERE AssocClass=Win32_LoggedOnUser Role=Antecedent")
        
'// Iterate through the session id's
For Each objLogonSession In colLogonSessions
        Select Case objLogonSession.LogonType
                '// We only want LogonType of Interactive (2) or 
RemoteInteractive (10)
                Case 2, 10
                        '// Ensure we only have the 'current' session id since 
earlier 'stale' sessions for the user may still be present
                        Set colSessionProcesses = objWMI.ExecQuery("ASSOCIATORS 
OF " & _
                        "{Win32_LogonSession.LogonId=" & 
objLogonSession.LogonId & "} " & _
                        "WHERE AssocClass=Win32_SessionProcess Role=Antecedent")
                        If colSessionProcesses.Count > 0 Then
                                strSessionId = objLogonSession.LogonId
                                dtmSessionStart =  
WMIDateStringToDate(objLogonSession.StartTime)
                                intLogonType = objLogonSession.LogonType
                                Exit For
                        End If
                Case 11, 12
                        '// Reserved for future use. These LogonTypes identify 
cached interactive logons.
                Case Else
                        '// We only care about interactive logons. Do nothing.
        End Select
Next

Set colSessionProcesses = Nothing
Set colLogonSessions = Nothing
Set objWMI = Nothing

MsgBox _
        "Username: " & strUser & vbCRLF & _
        "Domain: " & strDomain & vbCRLF & _
        "LastLogon: " & dtmSessionStart & vbCRLF & _
        "LogonType: " & intLogonType & vbCRLF & _
        "SessionID: " & strSessionID, 0 + 64, "Logon Information"

'===============================================================
'Clear variables, terminate script
'===============================================================

Set wsh = Nothing
Set wsn = Nothing
Set fso = Nothing

WScript.Quit

'===============================================================
'Declare procedures/functions/classes
'===============================================================

'--------------------
Function WMIDateStringToDate(dtDate)
'--------------------
'Returns a WMI formated date as a variant of subtype date.

On Error Resume Next

WMIDateStringToDate = CDate(Mid(dtDate, 5, 2) & "/" & _
        Mid(dtDate, 7, 2) & "/" & Left(dtDate, 4) _
        & " " & Mid (dtDate, 9, 2) & ":" & Mid(dtDate, 11, 2) & ":" & 
Mid(dtDate,13, 2))
End Function

Other related posts: