Clearing all Connections via command line

  • Thread starter Thread starter Christopher Johannsen
  • Start date Start date
C

Christopher Johannsen

I would like to clear all the connections via script or batch file but
cannot find any information on how to go about doing so. I have tried
using the RESET command but haven't been successful using it from a
script.
 
Matthew Harris has posted a command file that does this, in
microsoft.public.win2000.termserv.apps, around the end of april
this year.

Since that discussion used a great number of different threads
with different subjects, I won't give you the links, but a
synopsis. You can search for all articles in Google, use
"rwinsta" as the keyword and "Matthew Harris" as the Author.

The command from the console is:
for /f "tokens=2" %i in ('qwinsta ^| find /i "listen"') do
echo y | rwinsta %i

Be sure to substitute a %%i whereever you see %i appear in the
command, if you run it from a batchfile.

Matthews explanation:
The command is relatively simple, although the way I
constructed it makes it appear quite complex. First of
all, the For command runs the QWinsta command, which shows
all current sessions and listeners on your terminal
server. The output of the QWinsta command is then
searched, using the Find command, for the word "listen".
The word "listen" designates which sessions on your
terminal servers are the listeners, and consequently, if
you reset a listener, all sessions running under that
listener will be reset (thus, if all your sessions are rdp-
tcp, and you reset the rdp-tcp listener, all your sessions
will be reset). The For command then takes the output of
the Find command and looks at the second argument. This
argument is the session number of the listener. The For
command takes the argument and gives it to the RWinsta
command, which will then reset that session (the
listener). The Echo Y command merely says "yes" to
RWinsta asking if you are sure you know what you are doing
(and we do!)

After the command resets the session, everyone will
be able to log back on pretty much immediately.

Lastly...if you want to record what this script says, add
a >> output.txt to the end of the script. This will save
all output from the script to a file called output.txt.

--
Vera Noest
MCSE, CCEA, Microsoft MVP - Terminal Server
http://hem.fyristorg.com/vera/IT
--- please respond in newsgroup ---

(e-mail address removed) (Christopher Johannsen) wrote in
 
Back
Top