jump to navigation

Batch file to disconnect users on Terminal Services January 11, 2010

Posted by Cowboy in Uncategorized.
Tags: , , , ,
trackback

@echo off
rem Force all remote desktop sessions off
query session >session.txt
for /f “skip=2 tokens=3,” %%i in (session.txt) DO logoff %%i
del session.txt


@echo off
echo Force disconnected remote desktop sessions off
query session >session.txt
rem “skip two lines
remĀ  read 3 items
rem (default) delimited by space

rem the second token is ‘disconnected’ then logoff the session.
for /f “skip=2 tokens=2,3,4″ %%i in (session.txt) DO if ‘%%j’ == ‘Disc’ logoff %%i
del session.txt

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.