原因是 %~dp0 暴露在引号对之外,%~dp0 的展开优先于 %%i 的展开
办法1:开启变量延迟- @echo off
- set "s=%~dp0"
- for %%i in (1) do (
- setlocal enabledelayedexpansion
- reg add HKEY_CLASSES_ROOT\isfile\shell\open\command /ve /d "\"!s!v.bat\" \"%%1\"" /f >nul
- endlocal
- )
- pause
复制代码 办法2:把 %~dp0 放到 for 中- @echo off
- for %%i in ("%~dp0") do (
- reg add HKEY_CLASSES_ROOT\isfile\shell\open\command /ve /d "\"%%~iv.bat\" \"%%1\"" /f >nul
- )
- pause
复制代码
|