Shreenivas
Shreenivas

Reputation: 155

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

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?

Upvotes: 2

Views: 4529

Answers (2)

Alan Jebakumar
Alan Jebakumar

Reputation: 21

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

Upvotes: 2

MC ND
MC ND

Reputation: 70923

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

Upvotes: 2

Related Questions