2016-03-07

Logoff all users from Windows RDS/Terminal Server using cmd

How to logoff all users in server except administrator? Save sample below to a file named userslogoff.cmd to c:\temp directory:

query session |find /i "tcp#" | find /v /i "administrator" >session.txt
for /f "skip=1 tokens=3," %%i in (session.txt) DO logoff %%i
del session.txt


Run the sample by opening a Command Prompt window and typing the following command at the command prompt:

cd\
cd temp
userslogoff.cmd


Logoff command do not prevent uses for new logins, use command to disable new logins:

change logon /disable


Logons are re-enabled when you restart the system or use command to enable:

change logon /enable


/Geecoholic

No comments:

Post a Comment