date - 比较日期范围内的注册表字符串值
问题描述
我正在编写一个批处理脚本,它需要将注册表数据值字符串与今天日期的 ±3 天进行比较。
我的REG QUERY
返回值:
HKEY_LOCAL_MACHINE\Software\Wow6432Node\KasperskyLab\Components\34\1103\1.0.0.0\Statistics\AVState
Protection_BasesDate REG_SZ 27-08-2018 08-53-00
我需要输出到一个文件,这取决于它是否在范围内。
脚本:
REG QUERY "HKLM\Software\Wow6432Node\KasperskyLab\Components\34\1103\1.0.0.0\Statistics\AVState" /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:\ProgramData\CentraStage\AEMAgent\antivirus.json
:end
@exit
解决方案
此解决方案将此答案作为基础,因此请在此处发布更多问题之前查看此类答案...
@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 "HKLM\Software\Wow6432Node\KasperskyLab\Components\34\1103\1.0.0.0\Statistics\AVState" /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
)
推荐阅读
- android - 使用flutterdownloader的flutter android gradle错误
- sql - 使用 concat 和子字符串进行 SQL 连接
- ssl - NET::ERR_CERT_COMMON_NAME_INVALID 在 GoDaddy 中创建的域的 HTTPS 负载均衡器上加载 AWS ACM 证书时发生错误
- python - (Python) Discord 机器人代码返回“RuntimeError:无法关闭正在运行的事件循环”
- c# - 将列表的最后一个成员放在列表的开头
- php - 如何在多维数组中连接 2 个字符串?
- media-queries - 什么是覆盖媒体查询?
- python - 从 pandas 数据框列值的两侧添加 n 个值
- r - R - odbc - 如何关闭数据库连接?
- javascript - 遍历数组中的数据时出现语法错误