Recent

Author Topic: [work arounded]Naming daemons during instalation  (Read 412 times)

hrayon

  • Full Member
  • ***
  • Posts: 123
[work arounded]Naming daemons during instalation
« on: April 15, 2026, 01:35:28 am »
Is it possible to create a daemon project that accepts the name it should have in the Windows services window at the time of its installation as a parameter and that starts without error?

I can create a daemon project that is installed with "-i" but the name is fixed in the code. It works when I click "start", "stop" and is removable with "-u" without problems.

But using "sc" to install, I can get the name I want at the time of installation, but it doesn't "start" (error 1053).

Does anyone have a minimal example project that allows this?
fruits.exe -> "Banana Service" running
fruits.exe -> "Apple Service" running
fruits.exe -> "Orange Service" running

Maybe:
fruits.exe -i "Banana Service"
fruits.exe -i "Apple Service"
fruits.exe -i "Orange Service"
?
« Last Edit: April 16, 2026, 02:08:36 pm by hrayon »

Khrys

  • Sr. Member
  • ****
  • Posts: 438
Re: Naming daemons during instalation
« Reply #1 on: April 15, 2026, 06:54:51 am »
If you're willing to edit the registry (and have the permissions to do so), you could change  DisplayName  under  HKLM\SYSTEM\CurrentControlSet\Services\<YOUR_SERVICE>  to whatever you want.
You can use the built-in  fcl-registry  package to access the registry.

LeP

  • Sr. Member
  • ****
  • Posts: 304
Re: Naming daemons during instalation
« Reply #2 on: April 15, 2026, 08:46:39 am »
Try to look who is the unit used by your project (a system unit of fpc I think) where is calling the WinApi "CreateService" (I means where is used, not declared).

The third parameter is the "display name" of the service. Yoou can simply add it if it is not present (adding a property for example).

Code: Pascal  [Select][+][-]
  1. //Sample:
  2. CreateService(SvcMgr, Name, DisplayName, ........);
  3. //The "DisplayName" is the name that will be used to display / start / stop the service
  4.  
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

hrayon

  • Full Member
  • ***
  • Posts: 123
Re: [work arounded]Naming daemons during instalation
« Reply #3 on: April 16, 2026, 02:09:11 pm »
Thank you for the suggestions.
The ultimate goal was to reduce the work of manually editing service properties and compiling through the IDE. I solved this with .bat files and compilation via the command prompt. In some previous tests, I noticed that for Lazarus, the service name seems to need to be defined at compile time for things to work properly.

LeP

  • Sr. Member
  • ****
  • Posts: 304
Re: [work arounded]Naming daemons during instalation
« Reply #4 on: April 16, 2026, 03:36:10 pm »
[EDIT]: FPC has not a "BeforeInstall" event in svc component, so don't mind what I wrote ... sorry.

You should have an event "BeforeInstall" in your svc module, and in you serviceapp you can simply check in that event if a "command line parameter" is present (for example after "-i" ) and set the DisplayName value with that.
At runtime you can  use:

Code: Pascal  [Select][+][-]
  1. YourServiceApp -i Banana

to register the service with "Banana" display name.
It's an example, should not need to change the values in the IDE at designtime.
« Last Edit: April 16, 2026, 03:39:56 pm by LeP »
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

 

TinyPortal © 2005-2018