批处理 - 导出注册表项并计算项目和返回编号

时间:2014-10-15 18:40:58

标签: windows batch-file

我正在尝试编写批处理以将HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run和HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Run中的项目导出到文本文件,然后计算返回项目的数量和显示数字。

示例:它将Google Chrome REG_SZ xxxdataxxx返回到文本文件,然后我只想让它计算返回项目的实例,在这种情况下它将是1项。

谢谢!

2 个答案:

答案 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%