允许Windows服务与桌面交互 [英] Allow Windows service to interact with desktop

查看:649
本文介绍了允许Windows服务与桌面交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式启用允许服务与桌面交互?

How do I enable "Allow service to interact with desktop" programmatically?

在services.msc>操作>属性>登录>允许服务与桌面交互中,我可以使我的服务与桌面进行交互。我希望我的服务播放声音(MP3,WAV等)。

In services.msc > Action > Properties > Log On > Allow service to interact with desktop, I can enable my service to interact with the desktop. I want my service to play sound (MP3, WAV, etc.).

推荐答案

在这里,我将尝试一些自由来解释您的关键字提出的问题。将来,请花更多时间写您的问题,以使其他尝试阅读和理解它们的人也可以理解它们。

I'm going to take some liberties in here in trying to interpret your question from keywords. In the future, please spend more time writing your questions so that they make sense to another person who is trying to read and understand them.

日志下有一个复选框在Windows服务的属性窗口的选项卡上,该服务称为允许服务与桌面交互。 。如果尝试以编程方式选中该框,则需要指定 SERVICE_INTERACTIVE_PROCESS 标志nofollow noreferrer> CreateService API。 (请参见 MSDN )。

There is a checkbox under the Log On tab in the properties window for a Windows service that is called "Allow service to interact with desktop." If you're trying to check that box programmatically, you need to specify the SERVICE_INTERACTIVE_PROCESS flag when you create your service using the CreateService API. (See MSDN).

但是,请注意,从Windows Vista开始,严格禁止服务与用户直接交互:


重要提示:自Windows Vista
起,服务无法直接与用户交互。因此,不应在新代码中使用标题为使用交互式服务

部分中提到的
技术。

Important: Services cannot directly interact with a user as of Windows Vista. Therefore, the techniques mentioned in the section titled Using an Interactive Service should not be used in new code.

此功能已被破坏,传统观点表明您无论如何都不应该依赖它。服务并非旨在提供UI或允许任何类型的直接用户交互。 Microsoft一直在警告,由于可能的安全风险,自Windows NT诞生以来就应避免使用此功能。拉里·奥斯特曼(Larry Osterman)争论为什么总是一个坏主意。而且他是不是唯一的人

This "feature" is broken, and conventional wisdom dictates that you shouldn't have been relying on it anyway. Services are not meant to provide a UI or allow any type of direct user interaction. Microsoft has been cautioning that this feature be avoided since the early days of Windows NT because of the possible security risks. Larry Osterman argues why it was always a bad idea. And he is not the only one.

are 一些可能 解决方法,但是,如果您绝对必须具有此功能。但我强烈敦促您仔细考虑其必要性,并探索服务的替代设计。

There are some possible workarounds, however, if you absolutely must have this functionality. But I strongly urge you to consider its necessity carefully and explore alternative designs for your service.

这篇关于允许Windows服务与桌面交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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