创建Windows服务以打开程序-Delphi [英] Creating a Windows Service to open a program- Delphi

查看:318
本文介绍了创建Windows服务以打开程序-Delphi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi创建Windows服务。我的服务需要做的基本上是打开一个程序。
在我的代码中,我使用的是 WinExec(aux,SW_SHOWNORMAL); 。当我启动并运行该服务时,似乎没有任何反应,但是当我在TaskManager中查看时,该服务应打开的程序在列表中,并且在用户名列中显示为SYSTEM。

I'm creating a Windows Service with Delphi. What my service needs to do is basically open a program. In my code I'm using WinExec(aux,SW_SHOWNORMAL);. When I start and run the service nothing appears to be done, but when I look in TaskManager the program that my service should open is in the list and in the Username Column appears SYSTEM.

因此该程序正在打开,但没有显示在屏幕上。
我在Google上进行了一项研究,发现了一些功能,例如 CreateProcess ,但是我不知道如何使用它。
我在做什么错了?

So the program is opening but it doesn't show in the screen. I did a research in Google and found some functions like CreateProcess but I don't know how to use it. What am I doing wrong?

对不起,我的英语不好。

Sorry about my bad english.

推荐答案

服务始终在会话0中运行。默认情况下,由服务启动的进程在服务的Session中运行,除非该服务使用 CreateProcessAsUser()来运行

Services always run in Session 0. A process started by a service runs in the service's Session by default, unless the service uses CreateProcessAsUser() to run the process in a different Session.

在XP和更早的版本中,第一个登录的用户也在会话0中运行(随后的用户登录在会话1+中运行)。因此,如果该服务在安装时标记为交互式,并且运行的进程具有一个UI,则在会话0中运行的用户可以看到该UI。

In XP and earlier, the first user to log in also runs in Session 0 (subsequent users to login run in Sessions 1+). Thus, if the service is marked as Interactive when it is installed and it runs a process that has a UI, a user running in Session 0 can see the UI.

在Vista和更高版本,这不再可能。用户再也不会在会话0中运行,并且不能再将服务标记为交互式。这称为会话0隔离。服务现在必须使用 CreateProcessAsUser()才能在交互式会话中运行UI进程,以便用户可以看到它。

In Vista and later, this is no longer possible. Users never run in Session 0 anymore, and services cannot be marked as Interactive anymore. This is known as "Session 0 Isolation". A service must use CreateProcessAsUser() now in order to run a UI process in an Interactive Session so a user can see it.

有关更多详细信息,请参考MSDN:

Refer to MSDN for more details:

会话0隔离

会话0隔离对Windows服务和驱动程序的影响

从服务中调用CreateProcessAsUser()

在Windows Vista和更高版本的Windows Service中启动交互式过程

CreateProcessAsUser函数

这篇关于创建Windows服务以打开程序-Delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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