JSI Tip 3437. How do I display the previous logon date/time in a logon script?

If you run your logon script visible, you might want to display a previous logon message to your users, similar to:

Last logon was 03/01/2001 10:16 from computer name <Computer Name>.

To implement this display function:

1. Create a LastLogon$ share on your PDC.

2. Grant the Everyone full control on the share.

3. Set the NTFS permissions on the shared folder to:

    Authenticated Users - Read + Add (write).
    Creator Owner - Change.

Add the following to the end of your logon script:

@echo off
call :lastLogon <\\PDCname>
Goto end
set PDCname=%1
if exist "%PDCname%\lastlogon$\%username%.lli" type "%PDCName%\lastlogon$\%username%.lli"
if exist "%PDCname%\lastlogon$\%username%.lli" del /q "%PDCName%\lastlogon$\%username%.lli"
For /f "Skip=19 Tokens=*" %%i in ('Net user "%username%" /domain') do call :llifind "%%i"
goto end
set line=%1
set line=%line:"=%
if /i not "%line:~0,10%" EQU "Last logon" goto end
set display=Last logon was %line:~29,20% from computer name %computername%. 
@echo %display%>"%PDCname%\lastlogon$\%username%.lli"
NOTE: The first time a user logs on after you implement the script, nothing is displayed, but the the event is recored at %PDCname%\lastlogon$\%username%.lli.

NOTE: See WhereIs.

Hide 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.