在终端服务器上,服务如何在用户会话中启动进程? [英] On Terminal Server, how does a service start a process in a user's session?

查看:145
本文介绍了在终端服务器上,服务如何在用户会话中启动进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从终端服务器(在全球范围内)上运行的Windows服务中,我们希望能够启动在特定用户的终端服务器会话中运行Windows应用程序的进程.

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.

如何做到这一点?

Scenerio:Windows服务在启动时启动.用户登录到终端服务器用户会话后,根据Windows服务仅知道的一些条件,Windows服务希望在运行Windows应用程序的用户会话中启动一个进程.

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.

示例:我们想向用户显示"5分钟内关机"警告. Windows服务将检测到这种情况,并在每个用户会话中启动一个进程,该进程将启动显示警告的Windows应用程序.而且,是的,我知道还有其他显示警告对话框的方法,这是示例,我们要做的是更具侵入性的.

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.

推荐答案

您可以使用CreateProcessAsUser来执行此操作-但这需要一些努力.我相信以下步骤是基本的必需过程:

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

  • Get the user's session (WTSQuerySessionInformation).
  • Get a token for that user (WTSQueryUserToken).
  • Create a duplicate token for your use (DuplicateTokenEx).
  • Use the token to create an environment block (CreateEnvironmentBlock).
  • Launch the application with CreateProcessAsUser, using the block above.

启动该过程后,您还需要确保清理所有适当的句柄,令牌等.

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

这篇关于在终端服务器上,服务如何在用户会话中启动进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆