Multiple instances of the same service in Delphi -
i have have old windows service made in delphi has installed multiple times in same server, trying change code able change service name instaling service cannot make work.
i find information here , here it, , after study posts , make necessary modifications able install 2 services different names, services not start.
i post class responsible control service below (inherited tservice), know quite bit of code appreciate help.
procedure servicecontroller(ctrlcode: dword); stdcall; begin tvdavalanchedatacenterservice.controller(ctrlcode); end; function ttvdavalanchedatacenterservice.getservicecontroller: tservicecontroller; begin result := servicecontroller; end; procedure ttvdavalanchedatacenterservice.serviceloadinfo(sender : tobject); begin name := paramstr(2); displayname := paramstr(3); end; procedure ttvdavalanchedatacenterservice.servicebeforeinstall(sender: tservice); begin serviceloadinfo(self); end; procedure ttvdavalanchedatacenterservice.servicecreate(sender: tobject); begin serviceloadinfo(self); end; procedure ttvdavalanchedatacenterservice.servicestart(sender: tservice; var started: boolean); begin ftvdtrayicon := ttvdenvoytrayicon.create(self); setservicedescription; ftvddatacenter.tvdactive := true; end; procedure ttvdavalanchedatacenterservice.servicestop(sender: tservice; var stopped: boolean); begin freeandnil(ftvdtrayicon); ftvddatacenter.tvdactive := false; end; procedure ttvdavalanchedatacenterservice.serviceafterinstall(sender: tservice); begin setservicedescription; end; procedure ttvdavalanchedatacenterservice.setservicedescription; var areg: tregistry; begin if fdescriptionupdated exit; areg := tregistry.create(key_read or key_write); try areg.rootkey := hkey_local_machine; if areg.openkey(cnregkey+ name, true) begin areg.writestring('description', cnservicedescription); areg.closekey; end; fdescriptionupdated:= true; areg.free; end; end;
i using delphi xe , service need run in windows services.
thanks in advance
it's simple. have set name different each service.
you have:
name := paramstr(2);
displayname := paramstr(3);
and have change to:
name := baseservicename + '-' + getlastdirname;
displayname := baseservicedisplayname + ' (' + getlastdirname + ')';
where baseservicename constant name of service; baseservicedisplayname constant display name , getlastdirname function returns name of directory (last directory) extractfilepath(paramstr(0))
```
function getlastdirname: string; var aux: string; p: integer; begin aux := strdelslash(extractfilepath(paramstr(0))); p := strlastpos('\', aux); if p > 0 result := copy(aux, p + 1, length(aux)) else result := aux; end;
```
strdelslash deletes last slash; strlastpos searches last position of slash
Comments
Post a Comment