@ECHO OFF (set ip=%3) (set pcname=%3) (set drive=%2) (set num=00000%1) (set logfile=logs\%num%.txt) (set outputname=thread) (Set outputfile=.\log.csv) ::::::::::::::::::::::::::::::::::::::::::::::: :: 1) Set variables above. This file called as; :: newletter.bat count newletter LineFromCSV :: parameters are %1 %2 %3,%4... :: :: 2) Write a batch file that scans what you :: need locally, and uses the variables above. :: :: 3) Update the ":::Variable Part:::" section :: with your batch file. ::::::::::::::::::::::::::::::::::::::::::::::: ECHO. %* set num=%num:~-5% (SET pingnum=1) set pingtarget=%pcname% :PINGSTAT @for /F "delims=" %%A in ('ping -n %pingnum% -a %pingtarget%') do ( call :log xxxLx "%%A" @for /F "tokens=1,3,11" %%B in ("%%A") do ( @IF "%%B"=="Pinging" (SET resolvedip=%%C) @IF "%%B"=="Packets:" (SET percentloss=%%D) )) if DEFINED percentloss (SET percentloss=%percentloss:~1,-1%) if DEFINED resolvedip (SET ip=%resolvedip:~1,-1%) IF NOT "%percentloss%"=="100" GOTO :RESPONSIVE :: quarter ping failed. Check for partial connectivity. :: if full ping failed, exit. call :log xxxLx "%pcname% Failed ping [*%pingnum%]" @if "%pingnum%"=="1" ( (SET pingnum=4) call :log xxxLx "retrying with 4 pings . . ." GOTO :PINGSTAT ) call :log xxULC "%num%,%pcname%,%ip%,Unavailable. Lost %percentloss% percent of %pingnum% pings" GOTO :END :Responsive call :log xxxLx "%percentloss% percent Loss" IF ""=="%percentloss%" ( call :log xxULC "%num%,%pcname%,%ip%,Not Found" GOTO :END ) :: At this point, the machine is online and available ::::::::::::: connect drive ::::::::::::: if NOT exist %drive%:\nul GOTO ADDDRIVE :DRIVEEXISTS call :log xxxLx "%drive% exists . . ." @for /F "delims=" %%A in ('net use %drive%: /delete /y') do (call :log xxxLx "%%A") if exist %drive%:\nul ( ping -n 3 localhost >null goto :DRIVEEXISTS ) call :log xxxLx "%drive%:\nul doesn't exist" :ADDDRIVE call :log xxxLx "attaching \\%pcname%\c$ to %drive%:" FOR %%A in ("%USERID% %PASSWORD%","%pcname%\Administrator Password") do ( For /F "tokens=1,2" %%B in (%%A) do ( call :connect %%B %%C )) IF "%ERR%"=="0" goto :MAIN call :log xxxLC "%num%,%pcname%,%IP%,Can't Connect" Goto :End ::::::::::::: /connect drive ::::::::::::: :MAIN call :log xxxLx "Entering Main . . . " del netuse%drive%.txt -y :::::::::::::::::: Variable part :::::::::::::::::: :: Log success call :log SxxLC "%num%,%pcname%,%ip% :::::::::::::::::: /Variable part :::::::::::::::::: call :log xxxLx "Disconnecting . . . " net use %drive%: /delete /y GOTO :END :log :: SFUL (Success Failure Unavailable LogDetails CommonOutput) "Message" (set log=%1) echo %~2 if "%log:~0,1%"=="S" ECHO.%~2>>%outputname%.Updated.log if "%log:~1,1%"=="F" ECHO.%~2>>%outputname%.Noupdate.log if "%log:~2,1%"=="U" ECHO.%~2>>%outputname%.Unavail.log if "%log:~3,1%"=="L" if defined logfile ECHO.%~2>>%logfile% if "%log:~4,1%"=="C" if defined outputfile ECHO.%~2>>%outputfile% Goto :EOF :connect if EXIST %drive%:\nul Goto :EOF call Set USER=%1 call Set PWD=%2 call :log xxxLx "connecting as %USER%" if "%USER%"=="" ( net use %drive%: \\%pcname%\c$ > netuse%drive%.txt 2>&1 ) ELSE ( net use %drive%: \\%pcname%\c$ /USER:%USER% %PWD% > netuse%drive%.txt 2>&1 ) (set ERR=%ERRORLEVEL%) call :log xxxLx "netuse returns '%ERR%'" type netuse%drive%.txt if defined logfile type netuse%drive%.txt>>%logfile% IF "%ERR%"=="0" ( call :log xxxLx "Connected as %USER%." del netuse%drive%.txt -y goto :EOF ) FOR /F "tokens=3 skip=1" %%p IN ('Find /I "System Error" netuse%drive%.txt') DO (SET NETUSEERR=%%p) call :log xxxLx "NETUSEERR = %NETUSEERR%" FOR /F "delims==" %%p IN ('net helpmsg %NETUSEERR%') DO ( SET NETUSEDESC=%%p ) (SET NETUSEERR=[%NETUSEERR%] %NETUSEDESC:,=%) del netuse%drive%.txt -y call :log xxULx "%num%,%pcname%,%ip%,Doesn't Connect as %USER%. '%NETUSEERR%'" Goto :EOF :END call :log xxxLx "Done." del %0