Skip navigation

JSI Tip 9823. How can I return a date and time from a long integer FILETIME, like the Active Directory attribute lastLogon?

Some Active Directory date/times are stored as a long integer known as FILETIME, a count of 100 nanosecond intervals since January 01, 1601.

I have scripted FILETIME.BAT to return a date and time from a FILETIME.

The syntax for using FILETIME.BAT is:

call FILETIME FT DT TM

where:

FT is the long integer FILETIME, like the contents of LastLogon, LastLogonTimeStamp, and pwdLastSet.

DT is a call directed environment variable that will contain the date in MM/DD/YYYY format.

TM is a call directed environment variable that will contain the time in HH:MM:SS format.
FILETIME.BAT contains:
@echo off
if \{%3\}==\{\} @echo FileTime FT DT TM&goto :EOF
if exist "%TEMP%\FileTime.vbs" goto doft
@echo Dim WshShell, oExec, objArgs, exe, work >"%TEMP%\FileTime.vbs"
@echo Set WshShell = CreateObject("WScript.Shell")>>"%TEMP%\FileTime.vbs"
@echo Set objArgs = Wscript.Arguments>>"%TEMP%\FileTime.vbs"
@echo exe = "w32tm.exe /ntte " ^& objArgs(0)>>"%TEMP%\FileTime.vbs"
@echo set oExec = WshShell.Exec(exe^) >>"%TEMP%\FileTime.vbs"
@echo Do While oExec.Status = 0 >>"%TEMP%\FileTime.vbs"
@echo.      WScript.Sleep 100>>"%TEMP%\FileTime.vbs"
@echo Loop>>"%TEMP%\FileTime.vbs"
@echo work = Split(oExec.StdOut.Read(60))>>"%TEMP%\FileTime.vbs"
@echo Wscript.Echo work(3) ^& " " ^& work(4)>>"%TEMP%\FileTime.vbs"
:doft
If "%1" EQU "0" set %2=Never&set %3=Never&goto :EOF
for /f "Tokens=1*" %%a in ('cscript //nologo "%TEMP%\FileTime.vbs" %1') do (
 set %2=%%a
 set %3=%%b
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish