在系统关闭时从 Windows 服务调用 Windows 应用程序

发布于 2024-08-15 04:57:57 字数 309 浏览 14 评论 0原文

我正在用 C# 开发 .Net 3.5 中的 Windows 服务。该服务用于定期调用 Windows 窗体。现在我想将事件挂钩到服务,以便当用户尝试关闭系统时,Windows 窗体也会出现,从而阻止关闭过程。用户只能通过 Windows 应用程序关闭系统。

有没有办法在 Windows 服务中做到这一点?

编辑

我希望仅在Win 2000 和 Win XP 中完成此操作。

谢谢

I am developing a windows service in .Net 3.5 in C#. This service is used to periodically invoke a windows form. Now I would like to hook an event to the service so that when the user tries to shut down the system, then also the windows form will appear, preventing the shut down process. User can then only make the system shutdown through the windows application.

Is there a way to do this in a windows service?

Edit

I want this to be done in Win 2000 and Win XP only.

Thanks

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

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

发布评论

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

评论(1

夏有森光若流苏 2024-08-22 04:57:57

服务不应与用户会话交互。在 Vista 和 Win7 中,这实际上是被禁止的。与用户会话交互的正确方法是在会话中拥有一个与服务通信的应用程序,因此您创建定期启动表单的服务的方法是有缺陷的。阻止系统关闭听起来同样糟糕,Win7 会再次用暗淡的屏幕覆盖您的应用程序,建议用户杀死破坏者(即行为不当的应用程序,您的)。

按照您建议的方式改变用户体验的合法应用程序具有适当的 API 来执行此操作,例如 shell 替换。

Services should not interact with the user session. In Vista and Win7 this is actually prohibited. The proper way to interact with the user session is to have an application in the session that communicates with the service, so your approach to create a service that starts periodically a form is flawed. Preventing system shutdown sounds just as bad, and again Win7 will just overwrite your application with a dim screen suggesting the user to kill the vandal (that is the misbehaving appp, yours).

Legitimate applications that alter the user experience the way you suggest have proper APIs to do so, like shell replacements for example.

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