Creating a Windows service to open a program - Delphi

I am creating a windows service with Delphi. What I need to do is open the program. In my code I use WinExec(aux,SW_SHOWNORMAL); . When I start and start the service, nothing happens, but when I look in the TaskManager, the program that my service should open is in the list, and SYSTEM appears in the Username column.

So, the program opens, but it does not appear on the screen. I did a research on Google and found some features like CreateProcess , but I don't know how to use it. What am I doing wrong?

Sorry for my bad english.

+6
source share
1 answer

Services always start in session 0. The process started by the service starts in the default maintenance session, unless the service uses CreateProcessAsUser() to start the process in another session.

In XP and earlier versions, the first user to log in also starts in session 0 (subsequent log-in users run in 1+ sessions). Thus, if a service is marked Interactive when it is installed and it starts a process with a user interface, a user working in session 0 can see the user interface.

In Vista and later this is no longer possible. Users no longer work in session 0, and services can no longer be marked as "Interactive". This is called "Session 0 Isolation". The service should now use CreateProcessAsUser() to start the user interface process in an interactive session so that the user can see it.

See MSDN for more details:

Session Isolation 0

Impact of Session 0 Isolation on Services and Drivers in Windows

Call CreateProcessAsUser () from a service

Starting an interactive process from Windows Service on Windows Vista and later

CreateProcessAsUser Function

+6
source

Source: https://habr.com/ru/post/922603/


All Articles