Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to Log Off all Terminal Server Session Users using a batch file.  (Read 9109 times)

0 Members and 1 Guest are viewing this topic.

Aby

  • Guest
How to Log Off all Terminal Server Session Users using a batch file

In some occassions the administrators have to force log-off all user terminals, currently logged on to a windows server session. Below is a simple batch file that helps you out here. You can also run this command from command line. It would be easier for you if copy the code and save as a batch file.

Please follow below steps :

1. open a note pad

2. Copy the below code

---
query session >session.txt
for /f "skip=1 tokens=3," %%i in (session.txt) DO logoff %%i
del session.txt

---

3. Save the file as .bat as extension.

4.Click on the .bat file to see the result

Code Description:

Query Session creates a list of all sessions running on the Terminal Server, complete with Session ID numbers.
Within the batch file, this output is redirected to a text file. The FOR statement then parses each line of the text file, skipping the first line, and looking for the Session ID number found in the third column. It then places this variable into Logoff, resulting in that session being logged off.

-----
« Last Edit: March 21, 2014, 01:59:19 pm by Aby »