UnDiUdin
UnDiUdin

Reputation: 15384

Switching between standalone EXE and windows service

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?).

Upvotes: 5

Views: 1480

Answers (3)

John
John

Reputation: 103

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

Upvotes: 1

mj2008
mj2008

Reputation: 6747

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.

Upvotes: 0

philnext
philnext

Reputation: 3402

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.

Upvotes: 6

Related Questions