Posts Tagged ‘Microsoft’

Restarting Terminal Services Remotely

December 22nd, 2009

If you find yourself using terminal services a lot to manage various systems you will undoubtedly forget to logout of your sessions from time to time. Depending on the number of allowed and active sessions you could find yourself in a jam and unable to login.

I found myself in a jam and needed to restart terminal services remotely. Here is how I did it.

Yesterday evening, It occurred to me that a simple solution to this is to just restart the services from the command line. You might be wondering, since you can’t get in to run the command how this would work. You have two options:

  1. Execute a command from a web script (if you have ftp or rds access to an application server like ColdFusion or ASP .NET) *see below for more info

  2. Use PsExec (or PsService) part of the PsTools package from Microsoft. A nice collection of command line utilities for server administration I recommend you take the time to checkout.

To execute a command from a web script you will need to do two things. First create a batch file with the commands you wish to execute. Second write a script to securely execute those commands.


net stop “Terminal Services”

net start “Terminal Services”

REM echo reboot the machine

REM shutdown -r -t 0


<cfparam name=”url.key” default=”">

<cfif url.key eq “xya58IE9tsr”>

<cfexecute name=”#expandPath(“remote.bat”)#” variable=”foo”></cfexecute>




You will see the above script checks for a specific url.key in order to execute… you could easily limit this to a paticular IP or integrate another security method. Just remember not to leave it wide open or you just might have an unauthorized user executing your batch (probably on accident).

*Note that in this case the batch and cfm file reside in the same directory and execute permissions are given by default to each folder in CF. With ASP .NET you will need to make sure you have the ACL set correctly for IUSR or the Impersonated Account inside web.config.


If you don’t have access to an application server, rember to consider PsExec as an option. It is a free tool from Sysinternals, but I recommend you download it as part of a collection of PsTools.

To stop Terminal Services remotely, run :

psexec \\servername net stop “terminal services”

To start Terminal Services remotely, run :

psexec \\servername net start “terminal services”

*don’t forget to add your user account information for this to work. its [-u] & [-p] respectively. See /? or check out the July 2004 issue of Windows IT Pro Magazine for Mark’s article that covers advanced usage of PsExec.

Uncategorized , , ,