[Original] Windows script to log user, computer name, serial num

打印 被阅读次数

::login script used by system admins to collect user name,computer name,data,time and serial number for each login.
@echo off
if not exist "\dc-srvr01logsLoginsLoginLogs.csv" goto end
for /f "usebackq tokens=3 delims=," %%a in (`getmac /fo csv /v ^| find "cpip"`) do set MAC=%%~a
for /f "tokens=2 delims==" %%i in ('wmic bios get serialnumber /VALUE ^| find "Number"') do set SerialNumber=%%i
for /f "tokens=3,4,5 delims= " %%j in ('reg query "HKLMSoftwareMicrosoftWindows NTCurrentVersion" /v ProductName ^| find "ProductName"') do (set OS=%%j %%k %%l)
FOR /F "tokens=4 delims= " %%n in ('route print ^| find "0.0.0.0" ^| find "Default" /v ^| find "On-link" /v') do set localIp=%%n
for /f "tokens=2 delims==." %%c in ('wmic OS Get localdatetime /value ^|findstr /r [0-9]')do (set _date=%%c)
set year=%_date:~0,4%
set month=%_date:~4,2%
set day=%_date:~6,2%
echo %year%-%month%-%day%,%time%,%username%,%computername%,%MAC%,%localIp%,%OS%,%SerialNumber% >> \dc-srvr01logsLoginsLoginLogs.csv
:end

登录后才可评论.