5

I have written an application that on timer sends logs by mail. This application has a minimalistic user interface and once a config file is there it can start without the need of an interaction with the user.

Currently it is a VCL Forms application, but in some cases it would be good to have a service (in this way when running on a server there is no need to open a user session just to run the application).

What do you suggest for having both the worlds? In some simple scenario (smal organization, with just 3 pcs and no IT manager) a "non service" is good because it is easier to understand and to use, but in bigger organization the lack of service is a problem.

Is it possible to have a service and non service at the same time? How to achieve this? I don't want to make the deployment more complex, what I have in mind is some command line switch: when run with command line paramenters it can be a service, if not a normal app... How to do this?).

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • 5
    One of my answers to a different question gives code that does what you want: http://stackoverflow.com/questions/6594152 – David Heffernan Nov 14 '11 at 11:47
  • 4
    possible duplicate of [A standalone Delphi application that can also be installed as windows service](http://stackoverflow.com/questions/2387383/a-standalone-delphi-application-that-can-also-be-installed-as-windows-service) – gabr Nov 14 '11 at 13:24

3 Answers3

6

OK...the best way is to develop 'service' and 'non service' application in the same project. Like explained here : A standalone Delphi application that can also be installed as windows service. So you may use the same application as service or as stand alone application.

If you want to have both on the same PC, it is more complicated : you have to add, in the stand alone application, the functions :

  • Verifiy if the service is running and active.
  • If the service is running and active, you have to dialog with it instead of runing the stand alone process.
Community
  • 1
  • 1
philnext
  • 3,242
  • 5
  • 39
  • 62
1

I would create a control panel applet that sets uf the config needed for your application and then convert your app into a service. Your control panel applet could also start, stop and restart the service, etc.

You now have the best of both worlds.

John

John
  • 103
  • 1
  • 6
  • Do control panel applets still exist? I thought they kind of died out after Vista. I also struggle to see quite how a control panel applet solves anything. Perhaps I'm just being slow today. – David Heffernan Nov 14 '11 at 15:41
  • If you have to make a control panel applet, you would need Delphi XE2, and to build a 32 and 64 bit control panel applet. – Warren P Nov 14 '11 at 15:50
  • @WarrenP...32 bit CP applets will run on a 64 bit system/OS, A 32 bit service will also run on a 64 bit system/OS. – John Nov 15 '11 at 00:55
  • @David Hefferman... My Win 7 is laoded with Control Panel Applets! Unless your version of Cp Applet is different than mine. – John Nov 15 '11 at 00:56
  • @David... How a CP Applet solves his problem... And, "This application has a minimalistic user interface and once a config file is there it can start without the need of an interaction with the user." Seems perfect to me for a CP Appalet to do just a config. Maybe I am slow. Understand that this is Just my humble opinion and he was seeking advice. I have done it and have a 32 bit CP and service on Win server 2208 RS 64 bit. – John Nov 15 '11 at 01:03
0

What I do is have a separate project that is for development use only. I just create a form, then that creates the service and makes the calls expected.

  unit fTestHarness;

  interface

  uses
     uMyServiceModule,
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;

  type
    TfrmCentralTest = class(TForm)
      Label1: TLabel;
      Label2: TLabel;
      procedure FormCreate(Sender: TObject);
      procedure FormClose(Sender: TObject; var Action: TCloseAction);
    private
      { Private declarations }
    public
      { Public declarations }
    end;

  var
    frmTest: TfrmTest;

  implementation

  {$R *.dfm}

  procedure TfrmCentralTest.FormCreate(Sender: TObject);
  var
     bStarted : boolean;
  begin
     bStarted := False;
     MyService := TMyService.Create(self);
     MyService.ServiceStart(nil, bStarted);
  end;

  procedure TfrmCentralTest.FormClose(Sender: TObject; var Action: TCloseAction);
  var
     bStopped : boolean;
  begin
     MyService.ServiceStop(nil, bStopped);
  end;

  end.
mj2008
  • 6,647
  • 2
  • 38
  • 56