Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Windows Service to open a program- Delphi

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.

like image 866
Daniel Avatar asked Aug 10 '12 18:08

Daniel


People also ask

Can a Windows Service launch an application?

Windows Services cannot start additional applications because they are not running in the context of any particular user. Unlike regular Windows applications, services are now run in an isolated session and are prohibited from interacting with a user or the desktop.

How do I run a command as Windows Service?

Start service Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to start a service and press Enter: net start "SERVICE-NAME" In the command, replace "SERVICE-NAME" for the name or display name of the service.


Video Answer


1 Answers

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

like image 146
Remy Lebeau Avatar answered Sep 27 '22 21:09

Remy Lebeau