Logoff Disconnected Users

Posted on 2009-12-25
Last Modified: 2012-05-08
i have a windows server 2003 with sp2
we using that by terminal server..
so users connect this server via remote desktop connection
i did automatically logoff if idle time is 15 minutes..
but i want to log off disconnected users via script (like vbs)
so what can i do ?
thnx and regards...
Question by:asyab
    LVL 11

    Expert Comment

    by:Venugopal N
    LVL 82

    Accepted Solution

    Save the script below as LogoffDisconnected.cmd or Whatever.cmd.
    It's in test mode and will only display the "logoff" command(s) it would otherwise run. Simply remove the capitalized ECHO (so that line reads 'set test=') to run it for real.

    @echo off
    set Server=%ComputerName%
    REM set 'test' to an empty string instead of ECHO to run it for real:
    set test=ECHO
    for /f "tokens=1*" %%a in ('query session /server:"%Server%" ^| find /i "disc"') do (
      %test% logoff /server:"%Server%" "%%a" /v

    Open in new window

    LVL 1

    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now