Windows: batch file to logoff all other users (run as Administrator)
Posted by jpluimers on 2021/07/22
Based on zzz but filters current user, and listener session.
:: https://stackoverflow.com/questions/36715033/how-to-logoff-all-users-on-windows-from-command-line-as-a-domain-administrator :: The findstr bit filters out the current session (starts with ">") and session 65536 (which is the listener) for /f "skip=2 tokens=2,3 delims= " %%a in ('query session ^| findstr /v /b ">" ^| findstr /v "65536 Listen"') DO ( echo %%a|findstr /xr "[1-9][0-9]* 0" >nul && ( logoff %%a ) echo %%b|findstr /xr "[1-9][0-9]* 0" >nul && ( logoff %%b ) ) goto :eof
–jeroen






Leave a comment