Skip navigation

JSI Tip 0991. You hasn't logged off?


In tip 964, I scripted JSILLD.bat to report on user accounts that have not logged on since a given date.

JSINoLogoff.bat reports on logged on user accounts that have not logged off since a given date.

The syntax is:

JSINoLogoff <Drive:>\Folder\OutputFileName.txt \[YYYYMMDD\]

YYYYMMDD is an optional parameter, which defaults to today. If the user's Last Logon Date is earlier, they are reported.

The report format is:

ComputerName        UserName       YYYY MM DD   HH:MM

JSINoLogoff.bat contains:


@echo off
setlocal
If "%1"

"" goto syntax if exist %1 del /q %1 if "%2"

"" goto today set dte=%2 set XX=%dte:~0,4% if "%XX%" LSS "1993" goto syntax set XX=%dte:~4,2% if "%XX%" LSS "01" goto syntax if "%XX%" GTR "12" goto syntax set XX=%dte:~6,2% if "%XX%" LSS "01" goto syntax if "%XX%" GTR "31" goto syntax goto begin :syntax @echo Syntax: JSINoLogoff Output_File \[YYYYMMDD\] endlocal & goto end :today for /f "tokens=1,2,3,4* delims=/ " %%i in ('date /t') do set TDDAY=%%i&set TDMM=%%j&set TDDD=%%k&set TDYY=%%l set dte=%TDYY%%TDMM%%TDDD% :begin set output=%1 for /f "Skip=4 Tokens=*" %%i in ('net session') do call :parse "%%i" endlocal & goto end :parse set str=%1 set str=%str:"=% if "%str%"

"The command completed successfully." goto end set user=%str:~23,20%? set user=%user: =% set user=%user: ?=% set user=%user:?=% if "%user%"

"" goto end set cn=%str:~0,20% set /a cnt=0 for /f "Tokens=*" %%i in ('net user "%user%"') do call :parse1 "%%i" goto end :parse1 set /a cnt=%cnt% + 1 set ustr=%1 if %ustr%

"The command completed successfully." goto end if %cnt% NEQ 17 goto end set ustr=%ustr:"=% set txt=%ustr:~29,8% for /f "Tokens=1-3* Delims=/ " %%i in ('@echo %txt%') do set MM=%%i&set DD=%%j&set YY=%%k if /i "%MM%"

"Never" goto end if "%YY%" GTR "97" goto Y19 set YY=20%YY% goto mmm :Y19 set YY=19%YY% :mmm set /a XX=%MM% if %XX% LSS 10 set MM=0%XX% set /a XX=%DD% if %XX% LSS 10 set DD=0%XX% set YMD=%YY%%MM%%DD% if "%YMD%" GEQ "%dte%" goto end set user=%user% # set user=%user:~0,25% set txt=%ustr:~33,12% for /f "Tokens=1,2 Delims= " %%i in ('@echo %txt%') do set hhmm=%%j @echo %cn%%user% %yy% %mm% %dd% %hhmm% >> %output% :end

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