Link to home
Start Free TrialLog in
Avatar of SaLz
SaLz

asked on

Create Service function

hi, I need help creating a service, so the app will start as a service when windows loads.

needs to be a function or procedure, something like CreateService('App Name','Discription','C:\app.exe','Automatic');

Code Examples.

thxs
Sal.

ASKER CERTIFIED SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SaLz
SaLz

ASKER

anything more solid?
Maybe it doesn't help, no idea. But in these Demos there's one little service demo which doesn't use Delphi's service stuff, but pure win32 APIs only. It installs and uninstalls itself simply by getting started as a normal application:

http://madshi.net/MCHDemos.zip

Look in "system wide\HookProcessTermination\InjectService.dpr".
If the executable c:\app.exe is itself a service, created in Delphi, you can install it by executing

c:\app.exe /install
Avatar of SaLz

ASKER

ya thats the thing, 2 programs, 1 service, 1 app, anyway of having just 1 app with a service inside?

procedure TForm1.Form1Create(Sender: TObject);
begin
  if ParamStr(1) = '/install' then
    //install service
  else if ParamStr(1) = '/uninstall' then
    //uninstall service
end;

any code I can use to do this?
Do you have a TService component, added to your application ?
Avatar of SaLz

ASKER

I can add it, but how can I use it along these methods as above.

procedure TForm1.Form1Create(Sender: TObject);
begin
  if ParamStr(1) = '/install' then
    CreateService('App Name','Discription','C:\app.exe','Automatic');
  else if ParamStr(1) = '/uninstall' then
    RemoveService('App Name');
end;

how could I make a function like that 2 be called from my app to the TService unit?
If you want a part of your application to act as windows service, you MUST use the TService component, it has built-in methods for communication with SCM ( Service Control Manager ), which is manipulating the services. All the logic, which must be done by the service you must put inside the TService comonent. Then you should use methods from the unit WinSvc to register your service. Tell me if you need any help doing this.
Avatar of SaLz

ASKER

u know how to get the service handle in the service?

like in a form its application.handle & form1.handle, but how do I get the handle when its in a service?
try

service1.getservicecontroller