以下是修改后的代码:

@echo off
setlocal enabledelayedexpansion
set "results="

for /f "delims=" %%A in ('bcdedit /enum all ^| find /i "identifier" ^| find /i "-"') do (
    set "currentLine=%%A"
    set "isDifferent=true"
    
    for %%B in (!results!) do (
        if "!currentLine!" equ "%%B" (
            set "isDifferent=false"
            exit /b
        )
    )
    
    if "!isDifferent!"=="true" (
        set "results=!results!%%A"
    )
)

echo %results%
endlocal

修改说明:

  1. 添加了@echo off语句,用于关闭命令行回显。
  2. exit /b命令移动到了if语句的内部,以便正确退出内循环。
  3. 添加了echo %results%语句,用于输出结果。
  4. 添加了endlocal语句,用于结束本地变量的作用域。
批处理代码优化:提取bcdedit命令结果中的唯一标识符

原文地址: https://www.cveoy.top/t/topic/qnHQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录