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

99封情书 提交于 2020-01-07 03:12:49

问题


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

This above code is used for logoff remote desktop users where state is "Disconnected" in windows 2003.It will work perfect when I run in command prompt. But it will not run when I made a .bat file or .cmd file in windows 2003.so may know where i am going wrong?


回答1:


Inside batch files the percent signs used in the for replaceable parameters need to be escaped

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



回答2:


User585,

Yes, inorder to implement the for loop inside a bat/cmd session, you need to place the variable with

%%a

like this

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


来源:https://stackoverflow.com/questions/32223634/for-f-is-not-working-in-bat-file-but-it-works-with-command-prompt-in-windows-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!