for /f "tokens=3" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Maxthon3\Shell\open\command" /ve') do set str=%%~dpi 2>nul 1>nul
已经解决,用(for /f "tokens=3" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Maxthon3\Shell\open\command" /ve') do set str=%%~dpi) 2>nul 1>nul可以了
一般是将2>nul放到reg query的后面
一个隐患:如果路径中含有空格,tokens=3不能正确得到所需的值
仅供参考:
@echo off
for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Clients\StartMenuInternet\Maxthon3\Shell\open\command" /ve 2^>nul') do set str=%%~dpj
echo,%str%