Hi all,

My client is running a Win 2003 SP1 Server with many users accessing it through Terminal Services. Every night I have some scripts to run that only run correctly if all users are logged off from Terminal Services.

I am wondering if it is possible to script the logoff of all remote users in Terminal Services? If so, could someone please point me in the right direction for doing this.

I didn't see anything in the previous posts about this but maybe I missed.

Thanks for your attention


yea that's nice that they also tell you how to force console logoff.


The logoff of Console is the one thing they say you cannot do with this. Do you have a method of doing that?



whoops - you're right...they only say how to avoid the error message for the console session. i'm curious if a scheduled task would do it with the shutdown command right before your scripts run:

C:\Windows\System32\shutdown -l

I would also turn on the messenger service on the servers so I could script/schedule a broadcast a message to at least inform other admins that their session is going away. if you don't you're risking alarming your fellow admins unnecessarily. you could script with sc to enable/disable & start/stop messenger if you don't like having it run all the time. I would also use the same technique to shut down the TS service while running the scripts so nobody can login and interfere with your scripting requirements.

it's hard to find info about this because of the nature of console logins...this would only be admin users and thus normally you would never want to be kicking that kind of user out. obviously, you want your script to run, but something about blowing away admin sessions just doesn't sit right with me. i would at least let everyone know before i did that and also script in indicators so admins don't try to "fix" a problem which is really just your scripts doing their thing. for the console thing, to me, it makes more sense to request other admins not to leave stale console sessions, you know, use remote desktop only and broadcast a message to TS users five minutes before the force logoff of TS users runs.

another idea for the console thing, depending on number of servers you're running the script on, would be to use mstsc to log into the console session and check to make sure there's nobody logged in on the console before the script runs...this kinda defeats the point automating the tasks through scripting, though, since you'd have to login manually to do this.

mstsc /v <server: port> /console