Forums

 
HomeHomeRoyal TS V 1.xRoyal TS V 1.xToolboxToolboxRemote Rdp Session LogOff Script for RoyalTS 1.6Remote Rdp Session LogOff Script for RoyalTS 1.6
Previous
 
Next
New Post
1/12/2009 7:57 PM
 

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

 
New Post
1/13/2009 12:04 AM
 

 Hi!

Thanks for your contribution. Kudos, that script is great!

Just in case someone wonders, psexec.exe is not shipped with Windows and needs to be obtained from the technet site at Microsoft:

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

cheers, and keep the scripts coming...

Stefan


Stay in touch with code4ward.net:

Subscribe to our Blog RSS FeedFollow us on TwitterLike us on FacebookOur Google+ page
 
New Post
1/13/2009 9:45 AM
 

Wow - what is this cute boy @ Griesser doing the whole day? Producing fabulous scripts for all of us RoyalTS-fans!

Thanks a lot!

Greetings

gooogix

 
New Post
2/20/2009 8:32 AM
 

 Thank you for this script.  It works great.  The only change I had to make was in the task, I changed yourdomain to %domain% in order to get it to work properly.

 

Again thank you..  I would never have been able to put this together myself in any kind of reasonable time frame :)

 
New Post
2/26/2009 10:48 PM
 

Hi,

there is a command i have used in the past which finishes my RDP session, but doesn't actually log off the user/me it just gets rid of the screen lock and leaves the client computer as a normal working screen (not too sure if that makes sense).  Is there a way of getting this command to work as a task?  (normally i have it as a saved shortcut on the client PC).

%windir%\System32\tscon.exe 0 /dest:console

(i have only managed to get this to work on an XP machine, would love to know how to do the same on a vista machine)

 
New Post
6/11/2009 4:24 PM
 

To expand on this script.

Is there someway of scripting this command for every open session within RoyalTS???  Would need a list of open sessions, and then run through a loop to run the command on every session.

 

 
New Post
6/11/2009 5:10 PM
 

When you have configured the script as a task in Royal TS you can select a folder or the document to get the list of all your connections on the right hand side. In the list you can filter to only show active connections. Select all your active connections and start the task. That should do the trick.

cheers

Stefan


Stay in touch with code4ward.net:

Subscribe to our Blog RSS FeedFollow us on TwitterLike us on FacebookOur Google+ page
 
New Post
9/24/2009 5:52 PM
 

Has anyone tried this with RTS 1.6.7 installed on Vista SP2 64-bit? I can get it to work in XP. Maybe something related to the difference in the path of the app directory?

XP= C:\Program Files\code4ward\Royal TS

Vista x64=C:\Program Files (x86)\code4ward\Royal TS

 
New Post
9/25/2009 8:44 AM
 

 Hi,

you should also start Royal TS as Administrator by right-clicking Royal TS ans selecting Run As Administrator. By default, Royal TS starts as user, when you use tasks, it is recommended to start Royal TS as admin. You can also open the shortcut properties and configure it to always open as Admin.

Hope this helps.

cheers,

Stefan


Stay in touch with code4ward.net:

Subscribe to our Blog RSS FeedFollow us on TwitterLike us on FacebookOur Google+ page
 
New Post
10/2/2009 3:46 PM
 

I log into my laptop with a domain account that has local admin rights. UAC is turned off so the "Run as Administrator" in the shortcut options is grayed out. Even when i right-click the RTSApp.exe and run as admin the auto log-off script does not work. Will setting the RTS app logging level to verbose help debug this issue?



 
New Post
10/2/2009 3:55 PM
 

 I'm afraid the logging level will not help much. At this point, Royal TS has no control anymore what's happening. Royal TS will take the command line and just executes what it should do. You can try to manually start the process in the command prompt:

change to the directory C:\Program Files\code4ward\Royal TS (or whatever you configured in the task) and execute the following line:

psexec.exe \\$Host$ -c -u yourdomain\$User$ -p $Password$ LogOffRDPSession.cmd $Host$ $User$

of course you need to replace all your variables ($Host$, etc.) with real values, put the logoffrdpsessions.cmd in the working directory (or provide the full path to it) and see what happens.


Stay in touch with code4ward.net:

Subscribe to our Blog RSS FeedFollow us on TwitterLike us on FacebookOur Google+ page
 
New Post
12/31/2009 2:11 PM
 

I finally found an easy solution for this very annoying issue, and with the help of Windows 7 no less. I installed Royal TS on my laptop shortly after an upgrade from Vista SP2 to Win 7. A feature of 7 I noticed right away was the "Shift+Right Click" option to run applications as a different user...and this auto log off task worked like a charm just like it does under XP. Within a couple of weeks a lack of Win 7 drivers for my USB to VGA video adapter (for my 3rd monitor at work) pushed me to roll back to the HDD image I took of my Vista SP2 setup. Now I was right back to the same problem of this task not working.

THE SOLUTION: I found a tool straight from MS TechNet that did the trick.

Go and get ShellRunas at http://technet.microsoft.com/en-us/sysinternals/cc300361.aspx.
This little gem puts that very same "Shift+Right Click" option to run applications as a different user.
When I use this and run Royal TS under my domain admin account...IT WORKED!!!

 

HAPPY NEW YEAR!!!



 
New Post
12/31/2009 2:43 PM
 

 Didn't know that great little MS tool! Thanks for sharing this very useful info.

cheers and a happy new year to you too...

Stefan


Stay in touch with code4ward.net:

Subscribe to our Blog RSS FeedFollow us on TwitterLike us on FacebookOur Google+ page
 
Previous
 
Next
HomeHomeRoyal TS V 1.xRoyal TS V 1.xToolboxToolboxRemote Rdp Session LogOff Script for RoyalTS 1.6Remote Rdp Session LogOff Script for RoyalTS 1.6


spacer
dummy