?
Solved

Service making ??

Posted on 2001-08-13
20
Medium Priority
?
438 Views
Last Modified: 2010-04-04
Hi ..
I'd like to create a service ,and I want to know how ..
I want a simple demostration about the way of making it and how to add components and threads and programming codes..
also how to debug easyly ,and to start it ..

attach a simple example please ..
 
0
Comment
Question by:alim_maze
20 Comments
 
LVL 4

Expert Comment

by:fva
ID: 6379147
Try

http://www.tutorials.delphi-source.de/ntservice/sample_svc.zip

or

http://www.aldyn.ru/demos/0001/index.html

I use some other NT service skeleton, but I cannot find now a URL to that so I givie you these other two ones.

F.
0
 
LVL 17

Expert Comment

by:inthe
ID: 6379974
quite a few examples here:

http://www.jgsoftware.com/nt.htm

some versions of delphi have a wizard that
creates the service skeleton.
to install execute

project1 /install
using winexec or shellexecute from an installer prog and use
net start servicename
to start it
0
 

Author Comment

by:alim_maze
ID: 6383175
Hi fellows ..

I need an explanation about the service itself ,

mr F. am still checking your first link code,but second link explains service for Delphi4 and I use Delphi5.

also ,I need to know what is the service body step by step in easy way ..
and where I add components,and where I add code and how to start the service ,and where I choose it's name ..... ?

mr. inthe ,also your link points to Delphi4,and I use 5.

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
LVL 4

Expert Comment

by:fva
ID: 6383228
There should be no major differences on how to write the service between different Delphi versions. The main idea is that you create one app (usually a console-type one) that when runs it registers itself with the OS as a service. The OS then call some entry-point(s) (defined when registering) when performing different operations (like starting, stopping, pausing...)
Any example or component you will find just wraps this idea in a more (or less :) ) usable form as a unit or a full component.
Therefore, once you decide which "wrapper" to use, go ahead and try a simple example (usually provided with the "wrapper"). After that, refine the project adding more functionality as with any other project. Do not forget the special context where your project will run i.e.
- it has little or (even better) no interaction with the screen/kb,
- it runs usually under a special NT account, different than the admin (lower/different rights).

HTH,
F.
0
 

Author Comment

by:alim_maze
ID: 6383463
ok HTH,F. I will try your way now ..
0
 
LVL 4

Expert Comment

by:fva
ID: 6383527
Well, sorry for being lazy. HTH==Hope That Helps :)
F.
0
 

Author Comment

by:alim_maze
ID: 6383690
ok HTH,F. I will try your way now ..
0
 

Author Comment

by:alim_maze
ID: 6383855
the steps in your first link really does'nt help much.
I need similar steps compatible with delphi5  ,and how to debug,install,run/start,add code, and name the service .. etc.

I still need a solution.

Hah ha..
Mr.F ,you can't be lazy at all, and your rapid reply certifies that.

thank's
alim
0
 
LVL 4

Expert Comment

by:fva
ID: 6384001
OK, I found the better version I'm using, kindly made available as freeware by Colin Wilson. Check

http://www.jgsoftware.com/nt.htm

and get NTService.zip. I hope it'll be more useful than the others.

F.
0
 

Author Comment

by:alim_maze
ID: 6387262
I couldn't install (NTService.zip)in my delphi5 !
0
 

Author Comment

by:alim_maze
ID: 6387355
I couldn't install (NTService.zip)in my delphi5 !
0
 

Author Comment

by:alim_maze
ID: 6387372
I couldn't install (NTService.zip)in my delphi5 !
0
 

Author Comment

by:alim_maze
ID: 6387436
I couldn't install (NTService.zip)in my delphi5 !
0
 
LVL 4

Expert Comment

by:fva
ID: 6387473
On that page/URL there are links to 2 NT service ZIP's. One is intended to be installed into IDE and provides you with some additions to the IDE. It's nice, but it's for Delphi 4. Skip that.
The second one (named exactly NTservice.zip) is a sample project containing some units. One of the units contains a class handling NT service details. This is the ZIP you need. Just download it, unzip and open that project. Hopefully it will compile OK and it will produce an EXE that can be installed as a service. As far as I remember it does nothing but beeps for as long as it is active. After you get it to work you can start to learn how by reading the source and the comments there. After that you can try to modify it to do what you actually want to do.
If you have problems compiling I probably won't be able to help because I do not have a copy of D5 around to test. Sorry for that, but I hope you'll get over by yourself.

F.
0
 
LVL 4

Expert Comment

by:fva
ID: 6387482
Oh, by the way, if you hit refresh on the ExEx page that came in after you posted a comment you will (sometimes, in some configurations) post that comment again. That's why there are 4 identical comments from you above. :)
Use rather the "Reload question" link at the top of the page.

F.
0
 

Author Comment

by:alim_maze
ID: 6388016
first :
I new that some one will talk about this repeatence of submitting my comment , and that is you know ;)

and I thoght that <Reload Question> will repeat the submitting ,but I realized the opposite now !



second :
yes, this file is little better,although it gives compile errors :
-------------------------------------------

[Error] NTService.pas(406): Types of actual and formal var parameters must be identical
for the line :
[fExecuteThread := CreateThread (Nil, 0, @ExecuteHandler, self, CREATE_SUSPENDED, threadID);]
-----
[Error] NTService.pas(564): Types of actual and formal var
parameters must be identical
for the line : [ GetComputerName (machineName, size);]
-----
[Error] NTService.pas(617): Types of actual and formal var parameters must be identical
for the line : [  GetComputerName (machineName, size);]
-----
[Fatal Error] TestService.dpr(27): Could not compile used unit 'NTService.pas'
for the line :

[uses
  Windows, NTService in 'NTService.pas';]

-------------------------------------------


but comments written in the header of it's units are quite fine.
 
am trying to get benifit now ..
0
 
LVL 4

Expert Comment

by:fva
ID: 6388088
About the errors:
Probably the Win API functions there have changed definition from D3/D4 to D5. For reference, check your Windows.pas file for those functions. Here I post their definitions as they appear in D3's version of Windows.pas (where those units work):

function CreateThread(lpThreadAttributes: Pointer;
  dwStackSize: DWORD; lpStartAddress: TFNThreadStartRoutine;
  lpParameter: Pointer; dwCreationFlags: DWORD; var lpThreadId: DWORD): THandle; stdcall;

function GetComputerName(lpBuffer: PChar; var nSize: DWORD): BOOL; stdcall;

If the definitions in your windows.pas are the same then it's a compile switch (most probably {$T} )

If the compiler switch does not help then try to typecast the parameters when passing them
e.g.:
GetComputerName(PChar(machineName),DWORD(size));

F.
0
 

Author Comment

by:alim_maze
ID: 6388296
first :
I new that some one will talk about this repeatence of submitting my comment , and that is you know ;)

and I thoght that <Reload Question> will repeat the submitting ,but I realized the opposite now !



second :
yes, this file is little better,although it gives compile errors :
-------------------------------------------

[Error] NTService.pas(406): Types of actual and formal var parameters must be identical
for the line :
[fExecuteThread := CreateThread (Nil, 0, @ExecuteHandler, self, CREATE_SUSPENDED, threadID);]
-----
[Error] NTService.pas(564): Types of actual and formal var
parameters must be identical
for the line : [ GetComputerName (machineName, size);]
-----
[Error] NTService.pas(617): Types of actual and formal var parameters must be identical
for the line : [  GetComputerName (machineName, size);]
-----
[Fatal Error] TestService.dpr(27): Could not compile used unit 'NTService.pas'
for the line :

[uses
  Windows, NTService in 'NTService.pas';]

-------------------------------------------


but comments written in the header of it's units are quite fine.
 
am trying to get benifit now ..
0
 

Accepted Solution

by:
ThomasReimann earned 600 total points
ID: 6790396
The d4 examples are almost useless for d5.

Just select New/Service Application. Now you get a pseudo form where you can place components and also work with the object inspector. Put your code into OnExecute. You can install the service from command line: service.exe -install, uninstall with service.exe -uninstall.

You can start the service in the Computer management service list (Windows 2000).

It's difficult to debug a service, I suggest to create a normal app and then convert in into a service.
0
 

Author Comment

by:alim_maze
ID: 6891913
thank you very much !
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

569 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