简体   繁体   中英

On Terminal Server, how does a service start a process in a user's session?

From a Windows Service running on a Terminal Server (in global space), we would like to be able to start up a process running a windows application in a specific user's Terminal Server sessions.

How does one go about doing this?

The Scenerio: the windows service starts at boot time. After the user has logged into a Terminal Server user session, based on some criteria known only to the windows service, the windows service wants to start a process in the user's session running a windows application.

An example: We would like to display a 'Shutdown in 5 minutes' warning to the users. The windows service would detect this condition, and start up a process in each user session that starts the windows app that displays the warning. And, yes, I know there are other ways of displaying a warning dialog, this is the example, what we want to do is much more invasive.

You can use CreateProcessAsUser to do this - but it requires a bit of effort. I believe the following steps are the basic required procedure:

You'll also want to make sure to clean up all of the appropriate handles, tokens, etc., after you've launched the process.

Really late reply but maybe somebody will find this helpful.

You can use PsExec to launch an application on a remote (or local) server inside a specified session by using the following command:

psexec \\\\COMPUTER_NAME -i SESSION_ID APPLICATION_NAME

Where SESSION_ID indicates the session id in which to launch the application.

You will need to know what sessions are active on the server and which session id maps to which user login. The following thread provides a nice code sample for this exact problem: How do you retrieve a list of logged-in/connected users in .NET?

由于WTSQueryUserToken已经返回了主令牌,因此延迟答复但在上面的答案中没有必要使用DuplicateToken。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM