Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for pwdnoexp.bat

(view source code of pwdnoexp.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version (XP Pro or later)
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. SETLOCAL
  5. VER | FIND "Windows NT"   >NUL && GOTO Syntax
  6. VER | FIND "Windows 2000" >NUL && GOTO Syntax
  7.  
  8. :: Check command line argument
  9. IF     "%~1"=="" GOTO Syntax
  10. IF NOT "%~2"=="" GOTO Syntax
  11. ECHO."%~1" | FINDSTR /R /C:"[^\\]\\[^\\]" >NUL || GOTO Syntax
  12. ECHO."%~1" | FINDSTR /R /C:"[/?]"         >NUL && GOTO Syntax
  13. FOR /F "tokens=1,2 delims=\" %%A IN ("%~1") DO (
  14. 	SET Computer=%%~A
  15. 	SET User=%%~B
  16. )
  17. IF NOT DEFINED User GOTO Syntax
  18.  
  19. ECHO Checking current password expiration setting:
  20. WMIC.EXE /Node:%Computer% Path Win32_UserAccount Where Name="%User%" Get Name,PasswordExpires /Format:List | FIND "="
  21. ECHO.
  22. ECHO Setting password to never expire:
  23. WMIC.EXE /Node:%Computer% Path Win32_UserAccount Where Name="%User%" Set PasswordExpires="FALSE"
  24. ECHO.
  25. ECHO Checking new password expiration setting:
  26. WMIC.EXE /Node:%Computer% Path Win32_UserAccount Where Name="%User%" Get Name,PasswordExpires /Format:List | FIND "="
  27.  
  28. ENDLOCAL
  29. GOTO:EOF
  30.  
  31.  
  32. :Syntax
  33. ECHO.
  34. ECHO PwdNoExp.bat,  Version 1.00 for Windows XP and later
  35. ECHO Set a user's password to never expire
  36. ECHO.
  37. ECHO Usage:  PWDNOEXP  Computer\UserID
  38. ECHO.
  39. ECHO Notes:  For local accounts only, do not use for domain accounts.
  40. ECHO         Requires WMIC, which is a native command in Windows XP
  41. ECHO         Professional, Windows Vista and Windows Server 2003/2008.
  42. ECHO.
  43. ECHO Written by Rob van der Woude
  44. ECHO http://www.robvanderwoude.com
  45.  
  46. IF "%OS%"=="Windows_NT" ENDLOCAL
  47.  

page last modified: 2024-04-16; loaded in 0.0072 seconds