Solved

How to write an NT Service

Posted on 1997-06-16
12
249 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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