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?
1You can get sessionname from
query
for active connections than filter it withtasklist /FI "USERNAME ne administrator" /FI "SESSIONNAME eq XXX"
where is XXX active sessions you got fromquery
? – Alex – 2018-08-07T20:41:58.013Could 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 fromquery session
result, that start withrdp-tcp
from column SESSIONNAME and compare column ID with saved, if it doesn't match thenreset ID
to kill other rdp sessions. – Alex – 2018-08-07T21:17:28.307yes, 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