注册表中的过滤信息(批处理)

注册表中的过滤信息(批处理)

我编写了一个脚本,将 regedit 的值重新传输到 .txt 文件。我想知道是否可以过滤 .txt 中写入的“Exe 历史记录 - 存储”信息(目的是仅保留 C:\blablabla 或 D:\blablabla,我不想要 REG_BINARY)。

提前致谢 !

这是代码:

@Echo Off
:Main
cls
color c

ECHO 1 - Scan
ECHO 2 - EXIT
ECHO.

SET /P M=Choosen option : 
IF %M%==1 GOTO .Scan
IF %M%==2 GOTO .Exit

:.Scan
cls
set /P reg="Do you want to continue? (y/n) : "
if "%reg%" == "" goto :Main

(echo --------------------------[App Paths]--------------------------
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
echo.
echo --------------------------[Direct Input]--------------------------
reg query "HKEY_CURRENT_USER\SOFTWARE\Microsoft\DirectInput"
echo.
echo --------------------------[Exe History - Store]--------------------------
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store") > %UserProfile%\Desktop\Reg.txt 

pause
goto :Main

pause >nul

答案1

您可以在 VBScript 中使用正则表达式进行过滤,并从批处理文件中执行它,如以下示例所示:


@echo off & Mode 70,3 & color 0B
Title Extarcting EXE Paths from Registry Key
set Key_Store="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store"
Set "TmpFile=%Temp%\TmpFile.txt"
set "HistoryEXE=%temp%\HistoryEXE.txt"
Set "OutPutFile=%UserProfile%\Desktop\Reg_Paths_EXE.txt"
echo( & echo( Please wait a while ... Working is in progress...
(
    echo --------------------------[App Paths]--------------------------
    reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
    echo.
    echo --------------------------[Direct Input]--------------------------
    reg query "HKEY_CURRENT_USER\SOFTWARE\Microsoft\DirectInput"
    echo.
    echo --------------------------[Exe History - Store]--------------------------
)>"%temp%\App.txt"

Reg Query %Key_Store% /t REG_BINARY>"%TmpFile%"

Call :Extract "%TmpFile%" "%HistoryEXE%"
Copy "%temp%\App.txt" + "%HistoryEXE%" "%OutPutFile%">nul
@for %%a in ("%temp%\App.txt" "%TmpFile%" "%HistoryEXE%") do If Exist "%%a" Del "%%a"
If Exist "%OutPutFile%" Start "" /MAX "%OutPutFile%"
Exit
::****************************************************
:Extract <InputData> <OutPutData>
(
echo Data = WScript.StdIn.ReadAll
echo Data = Extract(Data,"\b(\w+).*.\.exe"^)
echo WScript.StdOut.WriteLine Data
echo '************************************************
echo Function Extract(Data,Pattern^)
echo    Dim oRE,oMatches,Match,Line
echo    set oRE = New RegExp
echo    oRE.IgnoreCase = True
echo    oRE.Global = True
echo    oRE.Pattern = Pattern
echo    set oMatches = oRE.Execute(Data^)
echo    If not isEmpty(oMatches^) then
echo        For Each Match in oMatches   
echo            Line = Line ^& Trim(Match.Value^) ^& vbcrlf
echo        Next
echo        Extract = Line
echo    End if 
echo End Function
echo '************************************************
)>"%tmp%\%~n0.vbs"
cscript /nologo "%tmp%\%~n0.vbs" < "%~1" > "%~2"
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
exit /b
::****************************************************

相关内容