How to select all SessionID in cmd (Wthout Administrator's SessionID)

0

I can show the active SessionID with the following command:

for /f "tokens=2-4" %a in ('"query session | find "Active""') do echo %b

While I can show disconnected SessionID changing the searched word (from "Active" to "Disc").

How can I find both active and disconnected SessionID excluding the administrator SessionID?

Squalo

Posted 2018-08-07T20:26:07.667

Reputation: 1

1You can get sessionname from query for active connections than filter it with tasklist /FI "USERNAME ne administrator" /FI "SESSIONNAME eq XXX" where is XXX active sessions you got from query? – Alex – 2018-08-07T20:41:58.013

Could you be more precise? I have multiple remote sessions that I will have to kill! Infact I need to extract all SessionID (of active and disconnected sessions) from query without Administrator's SessionID – Squalo – 2018-08-07T20:44:33.313

Ohh, I misunderstand, you want to kill rdp sessions except administrator... You can get session name for admin only first with query session administrator and save admin's ID then in a loop filter sessions from query session result, that start with rdp-tcp from column SESSIONNAME and compare column ID with saved, if it doesn't match then reset ID to kill other rdp sessions. – Alex – 2018-08-07T21:17:28.307

yes, but how can I isolate activated and disconnected sessionid? If i can store it in only one variable, after i can kill them with do reset session %b – Squalo – 2018-08-07T21:27:26.743

query session returning in column STATE status of connection, you can parse result by both columns SESSIONNAME & STATE and combine match by AND in IF statement inside loop – Alex – 2018-08-07T22:35:13.660

No answers