在终端服务器上,服务如何在用户会话中启动进程?

发布于 2024-08-02 11:52:38 字数 342 浏览 7 评论 0原文

从运行在终端服务器(在全局空间)上的 Windows 服务,我们希望能够启动一个在特定用户的终端服务器会话中运行 Windows 应用程序的进程。

如何去做这件事呢?

场景:Windows 服务在启动时启动。用户登录到终端服务器用户会话后,基于某些只有 Windows 服务已知的标准,Windows 服务希望在用户会话中启动一个进程来运行 Windows 应用程序。

示例:我们希望向用户显示“5 分钟后关闭”警告。 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒几许 2024-08-09 11:52:38

您可以使用 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:

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

淡看悲欢离合 2024-08-09 11:52:38

回复确实很晚,但也许有人会发现这有帮助。

您可以使用 PsExec 在远程(或本地)上启动应用程序)使用以下命令在指定会话内的服务器:

psexec \\COMPUTER_NAME -i SESSION_ID APPLICATION_NAME

其中 SESSION_ID 表示启动应用程序的会话 ID。

您需要知道服务器上哪些会话处于活动状态以及哪个会话 ID 映射到哪个用户登录。以下线程为这个确切的问题提供了一个很好的代码示例: 如何检索 .NET 中已登录/已连接用户的列表?

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?

寂寞花火° 2024-08-09 11:52:38

较晚回复,但在上面的答案中 DuplicateToken 是不必要的,因为 WTSQueryUserToken 已经返回主令牌。

Late reply but in the answer above DuplicateToken is not necessary since WTSQueryUserToken already returns a primary token.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文