![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Check Active Directory logins I want to check to see the last time an Active Directory user signed in to my domain. I also want to extend this to checking to see the last time a computer was used to sign in to the domain. Can VBScript do this? Thanks! Joe |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Check Active Directory logins "Joe Blow" <joe@xxxxxx> wrote in message news:Oy%230Y5qaJHA.4276@xxxxxx Quote: >I want to check to see the last time an Active Directory user signed in to >my domain. > > I also want to extend this to checking to see the last time a computer was > used to sign in to the domain. > > Can VBScript do this? > > Thanks! > > Joe > > i've unsed it in the past with some luck. your better off altering this script to out put into a text file and then import the results into a database where you can then query the results. LastLogonTimeStamp.vbs ' VBScript program to determine when each user in the domain last logged ' on. Domain must be at Windows Server 2003 Functional Level. ' 'cscript //nologo PCLastLogonTimeStamp.vbs > c:\pcoutput.txt ' ---------------------------------------------------------------------- ' Copyright (c) 2007 Richard L. Mueller ' Hilltop Lab web site - http://www.rlmueller.net ' Version 1.0 - March 24, 2007 ' Version 1.1 - July 6, 2007 - Modify how IADsLargeInteger interface ' is invoked. ' ' The lastLogonTimeStamp attribute is Integer8, a 64-bit number ' representing the date as the number of 100 nanosecond intervals since ' 12:00 am January 1, 1601. This value is converted to a date. The last ' logon date is in UTC (Coordinated Univeral Time). It must be adjusted ' by the Time Zone bias in the machine registry to convert to local ' time. ' ' You have a royalty-free right to use, modify, reproduce, and ' distribute this script file in any way you find useful, provided that ' you agree that the copyright owner above has no warranty, obligations, ' or liability for such use. Option Explicit Dim objRootDSE, adoConnection, adoCommand, strQuery Dim adoRecordset, strDNSDomain, objShell, lngBiasKey Dim lngBias, k, strDN, dtmDate, objDate Dim strBase, strFilter, strAttributes, lngHigh, lngLow ' Obtain local Time Zone bias from machine registry. Set objShell = CreateObject("Wscript.Shell") lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _ & "TimeZoneInformation\ActiveTimeBias") If (UCase(TypeName(lngBiasKey)) = "LONG") Then lngBias = lngBiasKey ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then lngBias = 0 For k = 0 To UBound(lngBiasKey) lngBias = lngBias + (lngBiasKey(k) * 256^k) Next End If Set objShell = Nothing ' Determine DNS domain from RootDSE object. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") Set objRootDSE = Nothing ' Use ADO to search Active Directory. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection ' Search entire domain. strBase = "<LDAP://" & strDNSDomain & ">" ' Filter on all user objects. 'strFilter = "(&(objectCategory=person)(objectClass=user))" strFilter = "(objectCategory=computer)" ' Comma delimited list of attribute values to retrieve. strAttributes = "distinguishedName,lastLogonTimeStamp" ' Construct the LDAP syntax query. strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" ' Run the query. adoCommand.CommandText = strQuery adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 60 adoCommand.Properties("Cache Results") = False Set adoRecordset = adoCommand.Execute ' Enumerate resulting recordset. Do Until adoRecordset.EOF ' Retrieve attribute values for the user. strDN = adoRecordset.Fields("distinguishedName").Value ' Convert Integer8 value to date/time in current time zone. On Error Resume Next Set objDate = adoRecordset.Fields("lastLogonTimeStamp").Value If (Err.Number <> 0) Then On Error GoTo 0 dtmDate = #1/1/1601# Else On Error GoTo 0 lngHigh = objDate.HighPart lngLow = objDate.LowPart If (lngLow < 0) Then lngHigh = lngHigh + 1 End If If (lngHigh = 0) And (lngLow = 0 ) Then dtmDate = #1/1/1601# Else dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _ + lngLow)/600000000 - lngBias)/1440 End If End If ' Display values for the user. If (dtmDate = #1/1/1601#) Then Wscript.Echo Left(strDN,15) Else Wscript.Echo Left(strDN,15) & "," & dtmDate End If adoRecordset.MoveNext Loop ' Clean up. adoRecordset.Close adoConnection.Close Set adoConnection = Nothing Set adoCommand = Nothing Set adoRecordset = Nothing Set objDate = Nothing |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Check Active Directory logins Perfect, thanks! I should have known to just check Richard's site... :-) j |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| check all Active Directory users for default password | VB Script | |||
| active directory | PowerShell | |||
| Active Directory | Vista security | |||
| Active Directory | Vista networking & sharing | |||
| active directory | PowerShell | |||