5

I have a Delphi application running in a server. This application do some critical work with my DB which is used in other applications and executes when a user logs in to Windows. It all is working fine, but, turns out the server's administrator sometimes reboot the server and does not log in to Windows. The server stays in Windows Login and my application doesn't start.

After a small research I decided to create a Windows Service to start my application even before a user logs in Windows. But, I have two forms. One form shows the Current Process that my application is executing and the other one edite a .ini file that its used to configure the first form.

What I need to be done is to create a service that starts my application before a user logs in Windows and after logging in, show my forms or open it but minimize it to System Tray.

Is it possible to use Windows Service with this behavior and minimize my forms to the System Tray?

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
Daniel
  • 309
  • 4
  • 13
  • 1
    In the end, you'll end up separating the gui from db work, following one of the suggestions in [this question](http://stackoverflow.com/q/1260181/243614) to interact with each other. – Sertac Akyuz Aug 14 '12 at 21:43

2 Answers2

16

A service cannot display a UI at all (including a System Tray icon) in Vista onwards, and it is discouraged in earlier versions. In all versions of Windows, you should be separating the UI out into its own non-service application that can be run by a logged-in user, manages the system tray icon for that user's tray, and communicates with the backend service as needed using any number of available IPC mechanisms (pipes, sockets, COM, RPC, WCF, etc).

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    Good advice! Please see ["Should a Windows Service have a GUI?"](http://www.coretechnologies.com/WindowsServices/FAQ.html#GUIServices) for more on this topic in the Windows Services FAQ. – CoreTech Aug 14 '12 at 22:26
  • Well I already knew that I coud not use UI with a service, I just wanted to confirm. I'm spliting my application in two applications. One as a service and another one as a simple configuration program with forms. Is there any specific configuration to a service starts even before an user log in Windows? Thanks for the answers, it will help me a lot. – Daniel Aug 15 '12 at 19:22
  • Assuming you are using Delphi's `TService` class, its `StartType` property controls when the service starts. It is set to `stAuto` by default, which means the service will start automatically during OS startup. – Remy Lebeau Aug 15 '12 at 19:36
  • I solve the problem. There is a service doing the hard work in background and a simple visual-application to configure a file used in service. I thank you all for the help. – Daniel Aug 17 '12 at 17:19
1

Well, you can have a form in a service, but is has to run as Administrator and must be set up as an interactive service.

I've used SVCOM to create nice services with tray icons and a form that can minimize to system tray.

Have a look here: http://www.aldyn.ru/products/index.html

Hope this helps

Peter Vrist
  • 53
  • 1
  • 5
  • 1
    SvCom looks like a handy tool, but technically it cannot use literally a form inside the windows service application. It still produces two separate applications and integrates them together. You can tweak your answer to mention that a tool like this can help in making such a connection possible, rather than saying something's possible which is actually not (with new technology). – Jerry Dodge Aug 16 '12 at 00:01