I’m looking for Delphi sample code to develope a Win32 Windows service which can be installed many times (with different Name).
The idea is to have 1 exe and 1 registry key with 1 subkey for every service to be installed.
I use the exe to install/run many service, every service take his parameter from his registry subkey.
Does anyone have a sample code?
We’ve done this by creating a TService descendant and adding an ‘InstanceName’ property. This gets passed on the command line as something like … instance=”MyInstanceName” and gets checked for and set (if it exists) before SvcMgr.Application.Run.
eg
Project1.dpr:
Unit1 (a TService descendant)
Usage:
Project1.exe /install
Project1.exe /install -instance=”MyInstanceName”
Project1.exe /uninstall [-instance=”MyInstanceName]
It doesn’t actually do anything – it’s up to you to write the start/stop server bits etc.
The ChangeServiceConfiguration call is used to update the real command line that the service manager calls when it starts up. You could just edit the registry instead but at least this is the ‘proper’ API way.
This allows any number of instances of the service to be run at the same time and they will appear in the service manager as ‘MyService’, ‘MyService (Inst1)’, ‘MyService (AnotherInstance)’ etc etc.