Skip to main content
23 events
when toggle format what by license comment
Jun 25, 2021 at 21:16 comment added duct_tape_coder This solution is not workable for me as the workstation indicates the user is "Active" under state even though the workstation is locked. Is there another solution or way to force the user into disconnected state when the workstation is locked?
Dec 10, 2018 at 17:53 comment added Guntis @eMansipater query command link not available anymore
Apr 23, 2011 at 0:17 history edited eMansipater CC BY-SA 3.0
added an alternative script for the other portion of the question.
Apr 15, 2011 at 1:07 comment added eMansipater @Jonas No problem! I will edit the answer to clarify both possible solutions for future reference, as soon as I can get to a Windows machine and verify the syntax for the script.
Apr 15, 2011 at 0:05 comment added Jonas @eMansipater: Oh, that's why the script didn't work with GTR when I tested! I logged in as user, switched to admin, and was, of course, not idle for long enough :). Thank you very much for your help!
Apr 14, 2011 at 23:51 history edited eMansipater CC BY-SA 3.0
simplified script for specific scenario
Apr 14, 2011 at 23:48 comment added eMansipater @Jonas I've had a chance to doublecheck the output of the query command and those parts of the script were so that the logout would only occur if the user had been idle for a set period of time. 'if %%d GTR 32' means to run the logoff command if the token %%d is greater than 32. Depending on use of remote desktop, etc. the "idle" token can appear in two places, which is why the script checks for both scenarios. Your modified version simply logs out any idle user no matter how long it's been. If I can get to a windows machine I can verify syntax.
Apr 14, 2011 at 18:05 comment added Jonas @eMansipater: also, it works as a .cmd file with %%.
Apr 14, 2011 at 17:57 vote accept Jonas
Apr 14, 2011 at 17:57 comment added Jonas @eMansipater: for /f "tokens=1-7 delims=,: " %a in ('query user ^| find /i "disc"') do logoff %b works as advertised when run from the command line as admin. Just out of curiosity: What do the if-clause and the GTR 32 mean that I left out? Were these important?
Apr 13, 2011 at 17:21 comment added eMansipater @Jonas a batch file uses "%%a", but to do the same thing at command line you type "%a" instead--that should help with debugging. I don't have a Windows machine handy to try the script on, so there might be something subtle wrong with it. You could try changing the "GTR 32 (logoff %%b)" commands to "echo logoff %%b" without the quotes, or "echo logoff %b" without the quotes if typing it in. That way it will print out the users it is trying to log off. If it prints garbage or nothing it will show the script is malformed. I'm afraid I don't know "query" output format by heart to check it.
Apr 13, 2011 at 13:46 comment added Jonas @eMansipater: If I right-click on the .cmd file and run as admin, nothing happens. If I run the for...-command from the command line, I get a %%a was unexpected at this time. Am I doing something wrong?
Apr 13, 2011 at 10:12 history edited eMansipater CC BY-SA 3.0
Tailored the solution to user's specific request
Apr 13, 2011 at 10:07 comment added eMansipater @Jonas exactly.
Apr 12, 2011 at 21:40 comment added Jonas @eMansipater: Ah, yes, switching with someone else logged in is indeed useful. Removing the loop means that I only keep the first and the third line, right?
Apr 12, 2011 at 2:37 comment added eMansipater @Jonas You could simply take the loop out of the script, then schedule it to be run every night at midnight. The key difference between the script as is and disabling fast user switching is that a user will still be able to log in if someone else has locked a computer. Would you like me to modify the code I supplied?
Apr 12, 2011 at 1:29 comment added Jonas @Moab: There are a few good uses for fast user switching: an admin can log on without the user needing to log off, or if one user goes for lunch, another can take over for an hour till the first user comes back and continues. I completely agree that training would be the best solution, but that's unfortunately not very feasible in my situation. Also, being a user on that machine myself at times, I like if things are easy for me :)
Apr 12, 2011 at 1:25 comment added Jonas @eMansipater: Thank you very much for your explanation. If I understand correctly, old users would be logged out as soon as another user is logged in for at most two minutes with this script. This is almost equivalent to disabling fast user switching. Is it possible, instead of waiting 120s, to have the script only run at, say, midnight, where it would log out everyone but the currently active user (other than start the service at midnight and wait 24h)?
Apr 11, 2011 at 22:29 comment added Moab Thanks eMansipater, the ultimate solution is user training with consequences, the easier you make it for users the worse they become.
Apr 11, 2011 at 21:12 comment added eMansipater @Moab disabling fast user switching means a non-admin cannot log in if the previous user has locked the screen. @Jonas A wise question-- the bit in parentheses is using the query command from support.microsoft.com/kb/186592 to find users who are disconnected by searching the phrase "disc", then logging them out. The choice command is waiting to only perform the operation every 2 minutes. There is no need for the 24 hour option since this script should only log out a user if another user has already logged in.
Apr 11, 2011 at 20:52 comment added Moab The best solution is to disable fast user switching, this will force a log off before the new user can log into their account.
Apr 11, 2011 at 20:32 comment added Jonas @eMansipater: Would you mind explaining what this does, and where I can set the 24 hours?
Apr 11, 2011 at 20:21 history answered eMansipater CC BY-SA 3.0