?
Solved

Create Service function

Posted on 2004-11-13
10
Medium Priority
?
811 Views
Last Modified: 2010-08-05
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.

0
Comment
Question by:SaLz
10 Comments
 
LVL 12

Accepted Solution

by:
esoftbg earned 2000 total points
ID: 12573784
0
 
LVL 2

Author Comment

by:SaLz
ID: 12573850
anything more solid?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 12586984
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".
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:tkalchev
ID: 12592136
If the executable c:\app.exe is itself a service, created in Delphi, you can install it by executing

c:\app.exe /install
0
 
LVL 2

Author Comment

by:SaLz
ID: 12592215
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?
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 12592296
Do you have a TService component, added to your application ?
0
 
LVL 2

Author Comment

by:SaLz
ID: 12592322
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?
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 12592344
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.
0
 
LVL 2

Author Comment

by:SaLz
ID: 12594303
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?
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 12594965
try

service1.getservicecontroller
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question