Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

18
  • @eMansipater: Would you mind explaining what this does, and where I can set the 24 hours?
    – Jonas
    Commented Apr 11, 2011 at 20:32
  • 1
    The best solution is to disable fast user switching, this will force a log off before the new user can log into their account.
    – Moab
    Commented Apr 11, 2011 at 20:52
  • 1
    @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. Commented Apr 11, 2011 at 21:12
  • 1
    @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. Commented Apr 13, 2011 at 17:21
  • 1
    @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. Commented Apr 14, 2011 at 23:48