Hello all fans of RoyalTS. Version 1.6 has one big new option. Tasks. Behind this options are most of the things you can imagine. One function i always missed is a logoff of one or better many active sessions with on click. I wrote a little script for that. Feel free to use it (at your own risk) and/or change it for your own needs.
Create a Task item in RoyalTS 1.6 with this script:
Taskname: What ever you want
Command: psexec.exe
Arguments: \\$Host$ -c -u yourdomain\$User$ -p $Password$ LogOffRDPSession.cmd $Host$ $User$
Working Directory: C:\Program Files\code4ward\Royal TS
Please remark: all commands and script must be in the Working Directory with the above settings. You can change this for your own needs.
The script:
Copy the part between 'Script Start' and 'Script End', paste it in Notepad and Save it as 'LogOffRDPSession.cmd'.
Usage: LogOffRDPSession.cmd Server User
Server = Server with the running RDP Session
User = User with sufficent rights
::Script Start
:: LogOff an RDPSession
:: written Andre Loehrer 12.01.09
::
:: Should run on Windows Server 2003 and higher (only tested on W2003)
::
:: Commands used:
:: CMD Shell extensions
:: QWINSTA.EXE MS OS Command
:: LOGOFF.EXE MS OS Command
:: PSEXEC.EXE MS/Sysinterals to execute the script on remotesystems, not in Script but usefull for running it in RoyalTS
::
:: Must exist:
:: none
::
:: Variables:
:: vBATCHHOME : Batch Homedir where all the stuff must be
:: vTARGETPATH : Target path of the generated file, must be the second command line parameter
:: %%i,%%j,%%k : Vars in For-Loop, containing values from output of QWINSTA.EXE
:: %%l,%%m
:: vSERVER : TargetSystem, first command line paramter, required
:: vUSER : User of the session which should be closed, second command line paramter, required
:: Feel free to use and change it to fit your needs
::
:: 1.00 - First Version
@ECHO OFF
CLS
::______________________
:: Set some vars
SET vSERVER=%1
SET vUSER=%2
::______________________
:: Simple syntaxcheck
IF "%vSERVER%"=="" GOTO SYNTAX
IF "%vUSER%"=="" GOTO SYNTAX
::______________________
:: Do the job
FOR /F "tokens=1,2,3,4,5 delims=# " %%i IN ('QWINSTA /server:%vSERVER%') DO IF [%%i-%%k]==[rdp-tcp-%vUSER%] LOGOFF %%i#%%j /SERVER:%vSERVER%
::______________________
:: For doku reasons ;-)
:: 1=protocol, 2=protocolsessionID, 1+#+2=sessionname, 3=username, 4=sessionID, 5=sessionstate
:: i j i#j k l m
::______________________
:: Finished
GOTO ENDE
::______________________
:: How to Use
:SYNTAX
ECHO.
ECHO Parameter missing: LogOffRDPSession Server User
ECHO.
ECHO Server: Server where the Session is
ECHO User: User with sufficient rights
PAUSE
GOTO ENDE
:ENDE
::Script End