In tip 531, we created JSIToday to parse today's date and JSIExpDT to parse a user's password expiration date.
You can configure when Windows NT issues a password expiration warning by using tip 141.
In tip 721, we built JSIDateM, a generalized date math routine.
If you want to issue your own password expiration warning, you need the ability to do DATE math. Create JSIExpire.bat:
Usage: JSIExpire "UserName" Days <Path>\notify.bat @echo off
set PWDX=N
If %1
"" goto syntax
set User=%1
set User=%User:"=%
if "%2"
"" goto syntax
set agea=%2
set /a agen=%agea%
if "%agea%""%agen%" goto dates
:syntax
@echo JSIExpire UserName Days <Path>\notify.bat
goto end
:dates
if %3
"" goto syntax
if not exist %3 goto syntax
call jsitoday
set TYMD=%TDYY%%TDMM%%TDDD%
net user %1 /domain | find /i "Password expires" > "%temp%\jsiexpire_%User%.log"
for /f "tokens=1,2,3,4,5* delims=/ " %%i in ('type "%temp%\jsiexpire_%User%.log"') do set XMM=%%k&set XDD=%%l&set XYY=%%m
REM If your date format is DD-MM-YY, use:
REM for /f "tokens=1,2,3,4,5* delims=- " %%i in ('type "%temp%\jsiexpire_%User%.log"') do set XDD=%%k&set XMM=%%l&set XYY=%%m
if /i "%XMM%" EQU "Never" goto end
call JSIDateM %XYY% %XMM% %XDD% - %2
if %AYMD% GTR %TYMD% goto end
:Notify
set PWDX=Y
call %3 %1 %2
:end
if exist "%temp%\jsiexpire_%User%.log" del /q "%temp%\jsiexpire_%User%.log"
Sample Notify.bat
@echo The password for account %1 expires on %NYY%-%NMM%-%NDD% which is within %2 days of %TDYY%-%TDMM%-%TDDD% (Today minus %2 is %XYMD%) REM You can use any form of notification that you wish: REM Net Send %1 Your password expires on the day %NDD% of month %NMM% in year %NYY%. Please change it today. REM or use a freeware command line mailer like Blat.JSIExpire also returns a PWDX evironment variable with the following values:
N=Does not expire within Days days.
Y=Does expire within Days days.