Solved

Service making ??

Posted on 2001-08-13
20
412 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 200 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now