for /f 在 .bat 文件中不起作用,但它在 windows 2003 中与命令提示符一起使用

for /f is not working in .bat file but it works with command prompt in windows 2003

for /f "tokens=1-7 delims=,: " %a in ('query user ^| find /i "disc"') do logoff %b

以上代码用于在 windows 2003.It 中状态为 "Disconnected" 的注销远程桌面用户,当我在命令提示符中 运行 时,2003.It 将完美运行。但是我在windows中制作.bat文件或.cmd文件时不会运行2003.so 2003.so 可能知道我哪里错了?

在批处理文件中,for 可替换参数中使用的百分号需要转义

for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do logoff %%b

用户 585,

年,为了在bat/cmd会话中实现for循环,您需要将变量与

%%a

像这样

for /f %%a in (.\hosts) do quser /server:\%%a