Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_log_access.bat

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

  1. :: Get current date in YYYYMMDD format if possible (XP Professional or later)
  2. FOR /F "skip=1 tokens=1-3" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Month^,Year /Format:Table') DO (
  3. 	SET /A Today = 10000 * %%C + 100 * %%B + %%A
  4. )
  5. IF ERRORLEVEL 1 SET Today=
  6. :: In case WMIC did not get the "sorted" date we'll have to get an "unsorted" date in regional date format
  7. IF "%Today%"=="" (
  8. 	REM Strip the leading day of the week from the date
  9. 	FOR %%A IN (%Date%) DO SET Today=%%A
  10. 	REM Remove the date delimiters
  11. 	SET Today=%Today:/=%
  12. 	SET Today=%Today:-=%
  13. )
  14.  
  15. :: Create a directory for today if it does not exist
  16. IF NOT EXIST \\Server\Logs\%Today% MD \\Server\Logs\%Today%
  17. :: Log the computer name and the date and time in a file with the user's name
  18. >> \\Server\Logs\%Today%\%UserName%.log ECHO %ComputerName%,%Date%,%Time%

page last uploaded: 2021-01-27, 16:12