2

I have a couple of DB servers that each run a RemoteApp that users launch to access said DB. The problem is that the application itself does not always exit gracefully when the user ends it, which leaves a remote session open and the user is unable to access said app again.

What I am trying to create a script that would terminate any current existing connection to each specific server (i.e. Script A would terminate for RemoteApp A, Script B would terminate for RemoteApp B).

Not sure if it adds an extra complication but the users are all working in a Remote Desktop environment (i.e. user connects to RDS1 or RDS2 and then launch RemoteApps to DB1, DB2 etc. from there).

All servers are running Windows Server 2012 R2.

1 Answers1

2

You could use Taskkill commands to kill a specific process on a specific server running as a specific username (see below).

Kill a process by targeting it based on...

  1. the remote server name which it's running
  2. the username running the process
  3. the process name on the remote server

Example Command

Be sure to set the appropriate values in the <RemoteServerName>, <Username>, and <appname.exe> parts of the taskkill command below accordingly for your environment and needs.

TASKKILL /S <RemoteServerName> /F /FI "USERNAME eq <Username>" /IM <appname.exe>

Further Resources

  • Taskkill

  • Taskkill /?

  • /S    system           Specifies the remote system to connect to.
    

    /FI filter Applies a filter to select a set of tasks. Allows "" to be used. ex. imagename eq acme

    /F Specifies to forcefully terminate the process(es).

    /IM imagename Specifies the image name of the process to be terminated. Wildcard '*' can be used to specify all tasks or image names

    Filters:

      USERNAME      eq, ne              User name in [domain\]user
                                        format