Reputation: 57
I am novice to batch scripting and I am wondering how it would be possible to search for rdp session using username and Disconnection using session id based on the first command output with help of some output modifiers or any other logic to select the session id and append it to " tsdiscon" using Batch script
Code :
C:\Users\vijay>query session vijay
SESSIONNAME USERNAME ID STATE TYPE DEVICE
>rdp-tcp#7 vijay 20 Active rdpwd
C:\Users\vijay>tsdiscon 20
Upvotes: 1
Views: 1737
Reputation: 57252
@echo off
set "name=vijay"
for /f "tokens=3" %%a in ('qwinsta "%name%"^|findstr /r /b /i ".*rdp"') do (
tsdiscon %%a
)
Upvotes: 1