john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Lastlogontimestamp vbs

REM John Pfeiffer 24oct07   VBS script to get last logon time and display (human form)
REM note that microsoft starts their clock at UT Jan 01, 1601 and measures every 100 ns
REM Original scripts from http://www.visualbasicscript.com/m_2327/mpage_1/key_/tm.htm
REM http://www.microsoft.com/technet/scriptcenter/topics/win2003/lastlogon.mspx

REM On Error Resume Next         REM continues even if a command returns an error

Set objUser = GetObject("LDAP://cn=administrator,cn=users,dc=williamscollege,dc=local")
Set objLastLogon = objUser.Get("lastLogon")
intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart 
intLastLogonTime = intLastLogonTime / (60 * 10000000)   REM 60 secs * 10,000,000 nanosecs per sec
intLastLogonTime = intLastLogonTime / 1440              REM 1440 mins per 24hr day
Wscript.Echo "Last logon time: " & intLastLogonTime + #1/1/1601#
REM It's off by an hour for people in London

REM Because the above didn't always work for me I instead used a hack
REM csvde -r objectclass=user -l lastlogon -f lastlogons.txt
REM unfortunately lastlogonTimeStamp & lastlogoff aren't recorded properly

REM intLastLogonTime = 128369361417343750       REM lastlogontimestamp administrator 15oct07?!?!?!

intLastLogonTime  = 128377034514062500          REM lastlogon administrator 24oct07 (better!)
intLastLogonTime = intLastLogonTime / (60 * 10000000)   REM 60 secs * 10,000,000 nanosecs per sec
intLastLogonTime = intLastLogonTime / 1440              REM 1440 mins per 24hr day
Wscript.Echo "Last logon time: " & intLastLogonTime + #1/1/1601#
REM It's off by an hour for people in London

  • « Netwdrive example.vbs
  • Input box sleep.vbs »

Published

Feb 6, 2010

Category

bat-vbs-perl

~178 words

Tags

  • bat-vbs-perl 51
  • lastlogontimestamp 1
  • vbs 1