Tuesday, November 23, 2010

Disconnect Terminal Services Sessions with ColdFusion

I was hit with this today so thought I would write it up quickly while it is still in my mind.  I needed to write an admin tool that could show Windows terminal services sessions and also could disconnect them.

There are Windows tools in place to do this so I just used <cfexecute> to call those.  This way, from a Web page, we can fire up the necessary tools.  Anyway, here we go...

To show the sessions:
<cfexecute name="c:\WINNT\system32\query.exe"
     arguments="session"
     variable="data"
     timeout="10">
</cfexecute>
<cfoutput>
<cfdump var="#data#">
</cfoutput>

To disconnect the sessions (for this project I only had to disconnect two licenses so I disconnected them, if there are more, you will need to disconnect each on in the arguments of the <cfexecute>  tag):
<cfexecute name="c:\WINNT\system32\tsdiscon.exe"
     arguments="1"
     timeout="10">
</cfexecute>

<cfexecute name="c:\WINNT\system32\tsdiscon.exe"
     arguments="2"
     timeout="10">
</cfexecute>

No comments:

Post a Comment