1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
@echo off
setlocal enabledelayedexpansion
set LOG_FILE=C:\Chemin\vers\votre\fichier\log.txt
:LOOP
for /f "tokens=1,2*" %%a in ('powershell -Command "Get-WinEvent -LogName System -FilterXPath '*[System[(EventID=6005 or EventID=6006 or (EventID=4624 and Message -like \'*an authentication package has been loaded*\') or (EventID=4624 and Message -like \'*an account was successfully logged on*\'))]]' | ForEach-Object { $_.TimeCreated }"') do (
for /f "tokens=1,2,3,4,5,6 delims=/: " %%x in ("%%c") do (
set "Day=%%x"
set "Month=%%y"
set "Date=%%z"
set "Hour=%%A"
set "Minute=%%B"
set "Second=%%C"
)
if %%a==6005 (
echo [Session ouverte le !Date!/!Month!/!Day! à !Hour!:!Minute!:!Second!] >> "%LOG_FILE%"
) else if %%a==6006 (
echo [Session fermée le !Date!/!Month!/!Day! à !Hour!:!Minute!:!Second!] >> "%LOG_FILE%"
) else if %%a==4624 (
echo [Session ouverte après redémarrage le !Date!/!Month!/!Day! à !Hour!:!Minute!:!Second!] >> "%LOG_FILE%"
) else (
echo [Échec de connexion le !Date!/!Month!/!Day! à !Hour!:!Minute!:!Second!] >> "%LOG_FILE%"
)
)
timeout /t 5 >nul
goto LOOP |
Partager