jeudi 1 février 2018

Issue in Batch file to check product exe date

We are transitioning our AV product and I am having issues where we run a batch file from the Windows LOGON script. I am trying to capture our AV's date revision, whether the old product is on the PC or the new product and if it is the new product, whether it is the current revision or not.

If it is the current product, i want it to log to a current or not current date, I have reviewed other Q's on Stackoverflow and found some examples i tried to mimic but it seems i have something screwed up. Both current version and non-current version are logging to both log files.

If anyone has any ideas i'd deeply appreciate it. I am a 30 Unix vet, I could whip sometime up in a shell script PDQ, but it's been a long time since i've done any complex DOS batch files.

DOS sucks, no builtin tools to parse files or set variables without jumping through a bunch of hoops.

@ECHO OFF CLS

setlocal

IF EXIST "C:\Program Files (x86)\Fortinet\FortiClient\FortiClient.exe" GOTO INSTALLED

IF NOT EXIST "C:\Program Files (x86)\Fortinet\FortiClient\FortiClient.exe" GOTO NOCLIENT

:INSTALLED 
dir "C:\Program Files (x86)\Fortinet\FortiClient\FortiClient.exe" > %temp%\dirlist.txt
SET filename="C:\Program Files (x86)\Fortinet\FortiClient\FortiClient.exe"
IF "%filedatetime:~0,-9%" == "01/08/2018" GOTO LOGCURRENT 
IF NOT "%filedatetime:~0,-9%" == "01/08/2018" GOTO NOTCURRENT 

:LOGCURRENT
IF EXIST %temp%\run.once GOTO INFO
copy nul %temp%\forticlientcurrentrev.txt
dir "C:\Program Files (x86)\Fortinet\FortiClient\FortiClient.exe" > %temp%\dirlist.txt
echo "%username%","%computername%","01/08/2018" > %temp%\forticlientcurrentrev.txt
REM type %temp%\MACinfo.txt >> "%temp%\forticlientcurrentrev.txt"
REM type %temp%\IPV4info.txt >> "%temp%\forticlientcurrentrev.txt"
type "%temp%\forticlientcurrentrev.txt" >> \\domain.tld\public\sophos\forticlientcurrentrev.txt 
type "%temp%\dirlist.txt" >> \\domain.tld\public\sophos\forticlientcurrentrev.txt 
copy nul %temp%\run.once 
GOTO EXIT

:NOTCURRENT
IF EXIST %temp%\notcurrent.once GOTO INFO
copy nul %temp%\forticlientnotcurrentrev.txt
dir "C:\Program Files (x86)\Fortinet\FortiClient\FortiClient.exe" > %temp%\dirlist.txt
ipconfig /all | find /i "physical address" > "%temp%\MACinfo.txt"
ipconfig /all | find /i "IP" > "%temp%\IPV4info.txt"
echo "%username%","%computername%","%filedatetime:~0,-9%" > %temp%\forticlientnotcurrentrev.txt
type %temp%\MACinfo.txt >> "%temp%\forticlientnotcurrentrev.txt"
type %temp%\IPV4info.txt >> "%temp%\forticlientnotcurrentrev.txt"
type "%temp%\forticlientnotcurrentrev.txt" >> \\domain.tld\public\sophos\forticlientnotcurrent.txt 
type "%temp%\dirlist.txt" >> \\domain.tld\public\sophos\forticlientnotcurrent.txt 
copy nul %temp%\notcurrent.once 
GOTO EXIT

:NOCLIENT
REM Collect System info for non-installed systems
ipconfig /all | find /i "physical address" > "%temp%\MACinfo.txt"
ipconfig /all | find /i "IP" > "%temp%\IPV4info.txt"
echo "%username%","%computername%"  >> "%temp%\forticlientlog.txt"
type %temp%\MACinfo.txt >> "%temp%\forticlientlog.txt"
type %temp%\IPV4info.txt >> "%temp%\forticlientlog.txt"
type "%temp%\forticlientlog.txt" >> \\domain.tld\public\sophos\computers_no_forticlient.txt

goto EXIT:

:INFO

:EXIT
EXIT

Aucun commentaire:

Enregistrer un commentaire