0

可能重复:
从 Windows 服务加载 GUI 应用程序

我需要一个在用户桌面上启动 .exe 的服务。我还需要在用户登录桌面后立即启动此服务。(Windows 7 平台)

我确实有 SENS 事件,但不确定如何将上述谜题放在一起。我也知道 Runkey 中的任何 .exe 都会在窗口启动时启动,但是如何将我的服务放入 Runkey 中?

任何帮助,将不胜感激。

谢谢你。

4

3 回答 3

2

Another option besides a windows service is writing a tray app which will start in the tray when the user logs in interactively. That eliminates the need of a windows service that's always running and has to detect when a log in occurs. It will start in the tray when they log in, runs as them, and you could offer gui in the tray app to start/stop the service.

Here's an S.O. post:

How can I make a .NET Windows Forms application that only runs in the System Tray?

If you want it always running even when not logged in interactively, then a windows service is the way to go.

于 2012-10-10T00:20:04.497 回答
0

从 Vista 开始不应该这样做,因为服务被设计为不能与桌面交互。这是有关该主题的更深入的文档。

http://msdn.microsoft.com/en-us/windows/hardware/gg463353.aspx

通常,您会将桌面可执行文件放在用户启动文件夹或类似文件夹中,并让它与服务通信。

这是影响您的段落:

对于更复杂的交互,开发人员应该将他们的 UI 代码移动到在用户会话中运行并处理所有 UI 要求的代理中。代理通过 RPC 或命名管道与服务通信。如果用户使用控制面板、Internet Explorer 或类似的 UI 体验启动 UI 交互,则该 UI 体验应启动代理。然后代理处理所有 UI 交互。如果需要 UI 但用户未启动,则服务必须请求代理启动任何所需的 UI,而不是尝试自行启动该 UI。在服务必须启动用户交互并且代理尚未运行的极少数情况下,服务应调用 CreateProcessAsUser API 来启动代理。然后代理可以启动所有 UI 交互。

于 2012-10-10T00:23:53.930 回答
0

您将需要 Windows 服务,请查看http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.80%29.aspx。在服务中,您将需要检测用户何时登录:如何在 c#(.net) windows 服务中检测 windows 启动或用户登录?

于 2012-10-10T00:09:44.103 回答