Batch script not functioning properly

April 23, 2018 at 05:58:54
Specs: Windows 7
query user | findstr -vi "USERNAME" > c:\Logged_User2.txt
for /f "tokens=2" %%i in (c:\Logged_User2.txt) Do logoff %%i
for /f "tokens=3" %%i in (c:\Logged_User2.txt) Do logoff %%i

Above batch script when executed the command screen keeps on scrolling.
The purpose of the above batch script is to log off all the users logged in terminal


See More: Batch script not functioning properly

Report •

#1
April 23, 2018 at 06:29:19
this sould work, add a line for every user you want to logoff

::start of test.bat
for /f "skip=1 tokens=1 delims=> " %a in ('query user "USERNAME"') do logoff %a
for /f "skip=1 tokens=1 delims=> " %a in ('query user "USERNAME"') do logoff %a
::end-of-test.bat

EDITED

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.225v/1915MHz memory@1.0v BiosModded

message edited by hidde663


Report •

#2
April 23, 2018 at 06:37:13
Rename your script to something other than logoff.

How To Ask Questions The Smart Way


Report •

#3
April 23, 2018 at 06:47:17
Hi,

I dont want to logoff user specific, it should logoff based on sessionid.
My script worked fine for few days but now its causing issue.

Thanks in advance


Report •

Related Solutions

#4
April 23, 2018 at 07:11:59

for %%A in (1,6,8) do for /f "skip=1 tokens=3 delims=> " %%a in ('query user "%%A"') do logoff %%a
replace this: 1,6,8 with the session numbers you want to log off

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded


Report •

#5
April 23, 2018 at 08:41:37
I cannot hardcode session ids as it will change everytime a user logs on

Report •

#6
April 24, 2018 at 01:29:07
you can also replace them with names :3, forgot to add
like so:

for %A in (Hidde,tets,reslut) do for /f "skip=1 tokens=3 delims=> " %a in ('query user "%A"') do logoff %a

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1430Mhz core@1.25v/1915MHz memory@1.0v BiosModded


Report •

Ask Question