About Terminal Server, Citrix, Delphi and other stuff
A little while ago I wrote an article on launching a process in another Terminal Session (http://www.remkoweijnen.nl/blog/2007/10/20/how-to-launch-a-process-in-a-terminal-session/).
The article didn’t have a demo app yet so I’ve attached it here.
How do you use it?
It’s a commandline tool and it’s called RunInSession. You need to specify at least the SessionId in which you want to launch the process and which process you want to launch. Optional is servername if you want to launch on a remote server. If you run it without parameters a dialog with possible parameters is shown:

Currently supported OS versions are Windows XP, 2003, Vista and 2008.
How does it work?
The program needs to run in the context of the Localsystem user, therefore it temporarily installs itselfs as service and start itsself. With the WTSQueryUserToken it obtains the Primary User token of the requested Terminal Session. Finally the process is launched with CreateProcessAsUser and the service deletes itsself.
RunInSession.zip (532)Related posts:
Active Directory Altiris bug Citrix Dell Delphi Exchange Exchange2003 Exchange2010 Hewlett-Packard HP iOS Jailbreak Java LinkedIn Linux MSI MySQL Navigation Objects Office Outlook Passat PowerPoint PowerShell referall was returned RNS315 RNS510 SasLibEx script slow Terminal Server ThinApp TSAdmin TSAdminEx VBS VCDS Vista VMWare Volkswagen Windows PE WLAN Wordpress WTSWaitSystemEvent wts_event_flush
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.
5 Responses for "How to launch a process in a Terminal Session #2"
[...] See and try it out here. [...]
[...] a commandline tool that must be run in the target session (tip: use my RunInSession tool). When you launch it, it will “listen” in a console [...]
Hi Remko,
Hope you are well, as always you’re the first port of call for anything Delphi\RDS related!
Just wondered if you ever came up against the 32\64bit bug in XP\Server 2003 where a 32-bit service\application cant call WTSQueryUserToken on a 64-bit version of the OS?
I’ve build a TS\RDP recorder app but falls over when making this call, annoying as Microsofts answer is simply to rebuild your app with a 64-bit compiler!
See: http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/9826c3ff-0e0b-489e-8343-e811826b03a3/?prof=required
Not sure if you were able to get around this at all. If not it’s worth noting, although I understand Server 2003 is proper old school!!
Hope you’re well, take care Remko…
Ross
Hello Ross,
The only way is to use direct rpc calls to termsrv.dll.
You can find more info in this article
http://www.remkoweijnen.nl/blog/2011/01/29/querying-a-user-token-under-64-bit-version-of-2003xp/
Ha ha, that’s absolutely amazing daNIL, talk about the EXACT answer to the question I was asking!! Man you guys are awesome.
I am going to check this out now and see if I can get it going.
Guys keep up the good work, there is so much here that has got myself and many other Delphi guys out of trouble. It’s blogs like this that keep Delphi going, let’s hope with a 64-bit compiler it’ll breathe new life into the language.
Thanks again!!!!
Ross
Leave a reply