$theTitle=wp_title(" - ", false); if($theTitle != "") { ?>
About Virtualization, VDI, SBC, Application Compatibility and anything else I feel like
8 Nov // php the_time('Y') ?>
A little while ago I wrote an article on launching a process in another Terminal Session (https://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 (5211 downloads )
8 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
https://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
Hi! I’m receiving this message could not obtain primary user token. What should I do ? I’m using PCExpanion ThinClient and the others sessions is running on them. I want this to open a webpage in all sessions. So it will be easy to open a website in all stations when some teacher wants it to. Sorry for the bad english.
Hi, thanks for tool. I wonder why it runs only programs from system32 folder? Eg it runs notepad.exe but it does not run my program, even if I specify the full PATH. If I copy my program into system32, it runs it, but I want to run it in a special folder.
Any hints? Thanks.
To bad it doesn’t work 🙁
From windows 7 machine i tried to control a session on a windows 2008 r2 machine.
The RuninService service could not be started?!?
Do i need to install a service somewhere?
Leave a reply