Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am writing a batch script which needs to compare registry data value string with ±3 days of todays date.

My REG QUERY returns a value:

HKEY_LOCAL_MACHINESoftwareWow6432NodeKasperskyLabComponents3411031.0.0.0StatisticsAVState
Protection_BasesDate    REG_SZ    27-08-2018 08-53-00

I need to output to a file, depending if it is within the range or not.

Script:

REG QUERY "HKLMSoftwareWow6432NodeKasperskyLabComponents3411031.0.0.0StatisticsAVState" /v "Protection_BasesDate" | Find "2018"
IF %ERRORLEVEL% == 1 goto end
If %ERRORLEVEL% == 0 goto makefile

:makefile
echo "{"product":"Override Antivirus","running":true,"upToDate":true}" > c:ProgramDataCentraStageAEMAgentantivirus.json

:end
@exit
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
203 views
Welcome To Ask or Share your Answers For Others

1 Answer

This solution takes this answer as base, so please review such an answer before post further questions here...

@echo off
setlocal EnableDelayedExpansion

rem Define the "Date to Julian Day Number" conversion function
set "DateToJDN(YMD)=( a=(YMD), y=a/10000, a%%=10000, m=a/100, d=a%%100, a=(m-14)/12, (1461*(y+4800+a))/4+(367*(m-2-12*a))/12-(3*((y+4900+a)/100))/4+d-32075 )"

rem Get the JDN of today's date minus/plus 3
for /F "tokens=2 delims==" %%t in ('wmic os get localdatetime /value') do set "dateTime=%%t"
set /A "todayMinus3=!DateToJDN(YMD):YMD=%dateTime:~0,8%!-3, todayPlus3=todayMinus3+6"

reg Get the date from REG QUERY command; the assumed output format is: Protection_BasesDate    REG_SZ    27-08-2018 08-53-00
for /F "tokens=3-5 delims=- " %%a in (
   'REG QUERY "HKLMSoftwareWow6432NodeKasperskyLabComponents3411031.0.0.0StatisticsAVState" /v "Protection_BasesDate"'
) do set /A "BasesDate=!DateToJDN(YMD):YMD=%%c%%b%%a!"

if %BasesDate% geq %todayMinus3% if %basesDate% leq %todayPlus3% (
   echo Date in range
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...