Solved

Calling NT Service

Posted on 1998-07-07
16
192 Views
Last Modified: 2010-04-02
Hi experts,
I got a few functions (eg. function A,B,C,D) and i would like to put these A,B,C,D functions as a one
and only one Service (or Daemon)in NT Server. This service run on the backgroud to serve many application . If application #1 call or using the service, application #2 and the rest cannot access the service....Now i don't know how to call the service from application and also don't know how to determine which application is calling the service.
Can someone give me a guide? Thanks in advance!!!:)

Regards,
Softyan Here
0
Comment
Question by:softyan
16 Comments
 

Author Comment

by:softyan
ID: 1251549
Edited text of question
0
 
LVL 3

Expert Comment

by:elfie
ID: 1251550
I would recommend making a deamon process  that controls all the needed functions. Once a service is requested the deamon process can spawn a child process handling the requeted function. Once the function is finished the child process notifies the deamon telling that his service is available again.

So if another is asking for the service while it's still busy, the demaon process knowns is can either give an error message back, or just blocks the call until the service is free.

I once used this technique for writing a printer deamon servicing a number of printers, connected thru special hardware interfaces, which obviously could only be used by one program at a time.
0
 

Author Comment

by:softyan
ID: 1251551
hi elfie,
   Do u have any example that can show me how to do this?
0
 
LVL 3

Expert Comment

by:elfie
ID: 1251552
It were drivers i wrote for my previous employer, and currently i have no useful example, unless i spend some time to it.

If you need some sample programs, the best you do is reject my answer, and ask for some sample program.

0
 

Author Comment

by:softyan
ID: 1251553
What's the different between a driver and the solution u that u proposed?
0
 
LVL 3

Expert Comment

by:elfie
ID: 1251554
The software we wrote was part of a big project, in which we emulate a complete (out-dated) hardware (Nixdorf) On a UNIX environment.
One of the parts that we had to emulate was the printing facility that existed on the old hardware. For that we wrote a kind of spooling mechanism. But instead of what normal spooling is (request are queued but the programs who printed, can continue)
the emulation of the old hardware implied that that either the programs trying to print on a busy printer, either had to wait until sending their request, or just stop printing an retyr a bit later.

For this solution we made a deamon process (and a control file) so that we were able to see which 'printer'driver to use for which hardware device(printer). If the deamon process found that a printer driver was busy, it was returned a status back to the calling program. If the printer driver was not busy at the moment, the request was passed via the deamon process towards the printer driver. Then the program and printer driver set up their own socket connection, and teh program was able to print.
Once the printing was finished (a close operation of the printer), The printer driver send a request to the deamon telling that his service was free again.

The deamon process was listening on a global socket (defined in /etc/services). The start a printer driver, the deamon process does a 'fork', and then an exec of the correct printer driver.
The printer driver sets up a 'privat' listen queue, and send the number of 'privat' socket towards the demaon process.
If a program connects to the deamon, and the printer program is free, the deamon send the 'privat' socket number the program, which can directly connect the printer driver.

So we made a deamon process, that was controlling some (printer)drivers.


Hope this clarifies my previous comment
0
 

Author Comment

by:softyan
ID: 1251555
Thanks for helping, but since i'm using WindowsNT, i have to write a service to perform the task. I would like to know HOW the service is communicate with the application.
0
 
LVL 1

Expert Comment

by:saneesh100
ID: 1251556
Hai..
  I think u know how to make an NT service . Then u can pass data to be communicated through any inter -processs commmunication techniques like pipe or u can use sockets etc.
 for eg in sockets it can wait for a connection and do the work so that no tohers can access it at that time and after processign it can accept  next app's request.

 I think u have got an idea .. please let me know if any clarifications needed..
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:softyan
ID: 1251557
Your comment is what i want, but do u have the example program that clarify the thing u said. i.e. (socket program, no others can access it at the same time). I am new to socket programming, i don't know the internal things of a socket program. I need your help to guide me through.

Thanks in advance! :)
0
 
LVL 1

Expert Comment

by:Rajkumar_R
ID: 1251558
I think what you want is a sample program which shows how to write a NT service ! I will send you by mail. Then you can give me the points what do you think ..send me a mail if you want that sample code ! at  rajkumar.r@usa.net
0
 

Author Comment

by:softyan
ID: 1251559
I have the sample code of NT Service, but what i want is the previously comment that I said. Thanks!
0
 
LVL 1

Expert Comment

by:Arkadiy
ID: 1251560
Why don't you try using RPC? It lets you call the function in one process and have it executed in another. It is fairly simple to use as long as you do not pass complex parameters to your functions.
0
 

Author Comment

by:softyan
ID: 1251561
Sorry, because of some other reasons, i cannot use RPC.
0
 

Expert Comment

by:dwh3
ID: 1251562

Set up your program as a service. This will require you to create the program and then register it as a service with the SCM (Service Control Manager). This basically involves creating a service routine and a handler function to handle the other messages from the SCM. Your service routine will call the programs real code (what you want it to do).

How do you call the service? Your service, once running, will need to listen to requests for functions A, B, C, and D. This can be done using pipes or sockets. The service will block waiting to accept incoming requests, receive data via the chosen IPC mechanism, process the request and then block again. Any external programs will use this IPC mechanism to use the service.

How do you determine who is calling the service? In the message passed to the service which requests function A, B, C, or D simply have the client state who it is. This is just a matter of the definition for your application layer protocol.

 
0
 

Accepted Solution

by:
nari earned 100 total points
ID: 1251563
May be you can  use mutual exclusive mechanisms like CriticalSections (or)
mutex objects to synchronize the calls to your service.And also to determine which
application is calling the service ,you can add one more argument to your functions in
daemon process for pid(process identifier) if possible.Once you gets the call to the daemon process lock Criticalsection or mutex object and unLock them after you have done.In that way you can solve your problem
0
 

Author Comment

by:softyan
ID: 1251564
Actually, i already had the solution, but still thank those who give me the suggestion.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

760 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

23 Experts available now in Live!

Get 1:1 Help Now