我正在尝试编写批处理以将HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run和HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Run中的项目导出到文本文件,然后计算返回项目的数量和显示数字。
示例:它将Google Chrome REG_SZ xxxdataxxx返回到文本文件,然后我只想让它计算返回项目的实例,在这种情况下它将是1项。
谢谢!
答案 0 :(得分:0)
@echo off
setlocal EnableDelayedExpansion
set OUTPUT=reg_%RANDOM%.txt
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" | findstr "REG_" > %OUTPUT%
set COUNT1=0
for /f %%a in (%OUTPUT%) do (
echo %%a
set /a COUNT1=!COUNT1! + 1
)
echo number of items HKLM: %COUNT1%
@echo.
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" | findstr "REG_" > %OUTPUT%
set COUNT2=0
for /f %%a in (%OUTPUT%) do (
echo %%a
set /a COUNT2=!COUNT2! + 1
)
echo number of items HKCU: %COUNT2%
del %OUTPUT% 2> nul
set /a TOTAL=%COUNT1% + %COUNT2%
echo.
@echo total %TOTAL%
答案 1 :(得分:0)
试试这样:
@echo off
for /f %%a in ('reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Run"') do set /a $c+=1
for /f %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"') do set /a $c1+=1
echo HKLM -^> %$c%
echo HKCU -^> %$c1%