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.

LVL 2
SaLzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SaLzAuthor Commented:
anything more solid?
0
MadshiCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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

c:\app.exe /install
0
SaLzAuthor Commented:
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
tkalchevCommented:
Do you have a TService component, added to your application ?
0
SaLzAuthor Commented:
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
tkalchevCommented:
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
SaLzAuthor Commented:
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
tkalchevCommented:
try

service1.getservicecontroller
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.