简化的 For /f 脚本

简化的 For /f 脚本

如何简化下面的批处理脚本以使其更美观。我的意思是如何组合两个 For /f 函数!

set KEY=HKLM\SOFTWARE\Clients\StartMenuInternet
set F=Firefox
set G=Google
set E=MsEdge

for /f "tokens=5 delims=\" %%a in ('reg query "%KEY%" ^| findstr "%F%"') do set result=%%a 
for /f "tokens=1 delims=-" %%c in ("%result%") do set fire=%%c
if "%fire%" equ "%F%" (echo Firefox already installed
) else (
echo Browser not found
)
Pause

答案1

@echo off

set "_Browser=Firefox,Google,Microsoft.Edge"
set "_hKey=HKLM\SOFTWARE\Clients\StartMenuInternet"

for %%i in (%_Browser%)do reg query "%_hKey%" | findstr /i "%%~i" >nul && =;(
     echo/%%~i already installed!.. );= || timeout 2 | echo/%%~i not found!..

相关内容