Logoff sessions except console

batchlogoff-scripts

There is an application in a multi-user environment that can only be open in one session on a workstation. The users move around frequently from PC to PC, leaving the application open, and the workstation locked. Disabling user switching is determinant to productivity. I need the system to force logoff any user besides the Consul session. The session ID is a variable that cannot be predicted. This is what I got so far…

@ echo off

query session > c:\users\session.txt

powershell -Command "Get-Content c:\users\session.txt | Where-Object {$_ -notmatch 'console'} | Set-Content c:\users\session2.txt"

for /f "skip=2 tokens=2," %i in (c:\users\session2.txt) DO C:\Windows\System32\logoff.exe %i

The goal is to put this into a .bat to run at user logon so whoever is ACTUALLY using the computer can use the applicaton. Dataloss of the inactive session is no concern. Ideally, rdp-tcp and services would stay active sessions as well.

Best Answer

Well, this isn't quite what you're asking for but it's close: a means to have users logged off automatically when they're classed as idle:

https://4sysops.com/archives/automatically-log-off-idle-users-in-windows/