Creating a Windows Service to open a program- Delphi

谁都会走 提交于 2019-12-03 13:34:23

问题


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.

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.


回答1:


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.

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.

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.

Refer to MSDN for more details:

Session 0 Isolation

Impact of Session 0 Isolation on Services and Drivers in Windows

Calling CreateProcessAsUser() from service

Launching an interactive process from Windows Service in Windows Vista and later

CreateProcessAsUser function



来源:https://stackoverflow.com/questions/11907299/creating-a-windows-service-to-open-a-program-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!