Vijay
Vijay

Reputation: 57

RDP Session Disconnection using Batch Script

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

Answers (1)

npocmaka
npocmaka

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

Related Questions