Solved

How to write an NT Service

Posted on 1997-06-16
12
247 Views
Last Modified: 2010-05-18
Simple.
How do you write an NT Service?
How do you declare it as such to NT?
I assume the former is some type of DLL with certain declared functions, and the latter is a regisrty key, but some details would be useful!
(BTW the MS Development library seems to have no help on this subject...)
0
Comment
Question by:bcrotaz
  • 7
  • 3
  • 2
12 Comments
 

Expert Comment

by:brittain
ID: 1337091

Not so simple.

You're assumptions are fairly accurate.  Should be EXE.  The registry has entries (look HKEY_LOCAL_MACHINE \ System \ ControlSetXXX \ Services), but generally there are WinAPI routines to write them.

MSDN does have quite a bit on services.  Try searching for Service Control Manager, OpenSCManager(), CreateService(), etc.  Also, there is a helpful example of a COM based service named SECSVR.CPP on MSDN.

Coincidentally, I asked a Borland SE about built in support for services and he said it was coming, but had no definitive timeframe (next version???).

I realize this isn't a "solution", but to write a service you've quite a bit of research to do (read "security, threading, etc.).  FYI, we are planning work in this area and would be interested in talking about it offline.
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1337092
MSDN?
It would be nice to write a wizard/ drop-on component to create a service.
Maybe I'll look at that when I'm done.
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1337093
Actually, I'm not hugely worried about security etc, due to the very simple nature of the app.
It's just backing up certain files every so often.
The client tells it what and where.
It's a service so that it starts automatically.
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1337094
I think I need more help on this one.
Thanks for the ideas, maybe someone else has already done this in Delphi.
0
 

Expert Comment

by:brittain
ID: 1337095
Try the Delphi Super Page (http://sunsite.icm.edu.pl/delphi/).  I saw a component there from someone in Minsk.  The source is supposed to be available.  I've tried it, but it doesn't run under NT 4.0.

Even if you're not interested in "securing" your application, you need to look into NT security.  One of the biggest pains with writing NT services is the authentication / identity rules imposed by the NT Security Manager.
0
 
LVL 3

Expert Comment

by:sperling
ID: 1337096
You don't need to bother with security to get a basic service up and running. To backup files, however, you need an account and password that has access to the files to backup.

There's a lot of work required to get a service working properly using Delphi, especially if your app has any direct or indirect reference to the forms.pas unit, and therefore instantiates the Application object. See the question "NT Services and Delphi 2" in the "Previously Answered Questions" section for a unit containing the necessarry declarations. I also tried to explain how services work and are started/controlled in the answer to this question.

Regards,

Erik.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:bcrotaz
ID: 1337097
Aha!
Thanks.
I should have looked, really, shouldn't I?
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1337098
Erm...
It's not simple really, is it?
Do you know how to get hold of the component you talk about in the paq?
0
 
LVL 3

Expert Comment

by:sperling
ID: 1337099
It's not as simple as dropping components on a form and setting properties ;) It is a lot simpler than writing a device driver, a debugger or some tcp/ip server....

My comments on the PAQ merely tried to explain the order in which certain events takes place when a service is started and controlled. You'll need some trying and failing to get it running, but it is not very complicated once you grasp how the SCM executes and controls the service.

I don't know the current status of ServiceMaker, I just tested an early beta, but if it has been released you should find a post on usenet in the comp.lang.pascal.delphi.announce group.
 
I am planning to assemble a service skeleton and put it up on my web page, but it won't be done until sometime in august I believe. I seem to rememeber at least 3 or 4 different service examples posted on news, try searching with dejanews and you might come up with some useful links...

Regards,

Erik.
0
 
LVL 3

Accepted Solution

by:
sperling earned 100 total points
ID: 1337100
I decided to finish the service skeleton right now. Go have a look at my homepage. http://www.info-pro.no/sperling

Regards,

Erik.
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1337101
Thanks - I'll have a play!
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1337102
Needs more work than I expected.
I think I'll come back to this one later in the year.
A program in the startup folder will do for now.

Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

10 Experts available now in Live!

Get 1:1 Help Now