Solved

How to write an NT Service

Posted on 1997-06-16
12
248 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

21 Experts available now in Live!

Get 1:1 Help Now