We have a Windows Server 2012 / Windows 10 client domain environment. Our terminal server has various Remote Apps published and deployed to the end users machines.

Sometimes a user’s session freezes up and it needs forcefully disconnected, because simply closing the window and re-launching the remote app will just resume their frozen session.

So, we will log into the terminal server, open task manager, find the user, right click and Logoff to force kill their session.

I’d like to know if there is a script the users themselves can run to perform this same action…force kill their own Remote app session. This will free up our time and the user’s time if they can just do it themselves.

I’ve been trying to come up with something using qwinsta, but whatever I try will not work.

I was thinking I need to query the sessions on the terminal server (Server-TS)…somehow match the session with the current logged on user for that computer (perhaps %username% would work?)…funnel that session information to a variable…and then use some kind of kill/disconnect command to force close it.

Again, the goal is to allow a user on their own workstation the ability to force kill their own Remote App sessions so that an administrator doesn’t have to log into the terminal server, go into task manager, etc etc. each time an app freezes or glitches up.

Any help would be greatly appreciated!!!

3 Spice ups

Users should not have the access rights needed to kill a session on the server.

Your idea of querying and scripting might work for your admins so it will be easier for them to kill a session.

1 Spice up

The way this script would be launched would be through a program…they will NOT be able to see the script that’s running.
With that being said, is there a way to run a command which authenticates to the terminal server with administrator credentials that DOES have rights to kill sessions on that server…and then kill the session that matches the currently logged on user on that computer?

You’d have to hardcode them into it if you don’t want admin interaction and hardcoding credentials is almost never a good idea.

1 Spice up

This part… I don’t know. I’m not sure there’s a way to make that work.

Does configuring the server to logoff or end disconnected sessions after x minutes not work? That’s what I do.

I second this. You could hardcode the credentials into something like a VB script, then compile it into a binary. But then, you would still have credentials out in the wild.

I’ve zipped binary .exe files, and opened them with a Linux archive manager. You can see a lot of clear code that way.

I would resign myself to writing a script which can be customized per user, and save a folder full of them. When that user needs the reset, I could run the script myself.

Almost as if I’d thought of it myself.

I appreciate the responses. It doesn’t sound like there’s an easy way to simply let a user kill / force disconnect their own session via command line. Am I understanding correctly?

It just sucks that a user has to call our help desk, open a ticket, and wait for their remote session to be killed by an administrator.

@da-schmoo ​ I need it to be on-demand, unfortunately. I can’t have the users waiting for the timeout threshold…and I also cannot lower it because the users will sometimes switch computers and want to resume their sessions.

On the flip side of that, it sucks that your apps are freezing the sessions and causing this problem. Maybe you can talk to the app developer and have them fix their software? Then you won’t have to deal with this at all.

That’s a very good point. I should say that it only happens for a few random users once a week…generally it’s not a big problem. They work in healthcare and they hate delaying patients and other stuff to call in to kill the session…would rather be able to do it themselves and then move forward with their tasks.

Generally speaking, the application and terminal server work very well.

2 Spice ups