Writing a windows service api?

sao123

Lifer
May 27, 2002
12,653
205
106
I need to create a generic windows xp service which can effectively be a wrapper allowing a nonservice executable run as a service.


Does anyone know what type of interface a service needs to run in windows? What distinguishes a normal executable from a service executable?
 

Mday

Lifer
Oct 14, 1999
18,647
1
81
a registry entry. runservice or something like that iirc.

Its been a while since i read anything about it. As far as I recall, a service is like a TSR that runs before a user logs in. So any program that is placed in runservice executes before the log-on process takes place.

I'm just going to leave it at that for now, since I dont know what you want to do "exactly".

have you asked in software or operating systems (other forums here on anandtech forums)? Also, try asking on the arstechnica forums, NT Mojo or software colloquia or somejunk.
 

sao123

Lifer
May 27, 2002
12,653
205
106
What I'm really looking for is program structure.


Ok, here is a little experiment:
open a command prompt box:

type
cs.exe create "my service" binPath= "c:\program files\microsoft office\office10\powerpnt.exe" type= own type= interact
cs.exe start "my service"

you haver now created your own service which will run the powerpoint executable...
(to undo what you have just done just change start to stop, and create to delete)

Now, when you start your service with the above line, powerpoint will start up. But in a 30 second time, it will quit, and you will get an error. The service quit because it failed to take control. So windows is waiting for the service to call some type of control function in its api.

So, what i want to do, is code my service in c++/vb which can answer the take control as expected.
IE its not just any plain old program that can run as a service...a service must have a take control function to do something. What I need now...is documentation on apis or function headers to allow me to do this.
 

tinyabs

Member
Mar 8, 2003
158
0
0
Originally posted by: sao123
What I'm really looking for is program structure.


Ok, here is a little experiment:
open a command prompt box:

type
cs.exe create "my service" binPath= "c:\program files\microsoft office\office10\powerpnt.exe" type= own type= interact
cs.exe start "my service"

you haver now created your own service which will run the powerpoint executable...
(to undo what you have just done just change start to stop, and create to delete)

Now, when you start your service with the above line, powerpoint will start up. But in a 30 second time, it will quit, and you will get an error. The service quit because it failed to take control. So windows is waiting for the service to call some type of control function in its api.

So, what i want to do, is code my service in c++/vb which can answer the take control as expected.
IE its not just any plain old program that can run as a service...a service must have a take control function to do something. What I need now...is documentation on apis or function headers to allow me to do this.


A service is a program that extends the Windows functionalities. Many services like IIS, Disk, Security, Network and others extends Windows. It is not a TSR, by comparsions. Since a service is a process, you must use cross-process communication API such as RPC, Pipes, Socket and DCOM to communicate with a UI or other programs.

You must report your service status to Windows even if it started by Windows.

You can use Visual Studio or Borland C++ Builder to build a sevice. The correct way is to develop a containment class that contains Start, Stop, Pause methods and dummy methods for EventLog and status reporting. It will save you troubles because compiler can't debug a Service natively; test the containment class with a Console App.

Look into your compiler help file or MSDN for documentation,
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
I dont know if I can say anything that will help. But try Vbforums.com, they have some pretty good programming help there.
 

sao123

Lifer
May 27, 2002
12,653
205
106
I have seen many programs install themselves as a service.
norton antivirus
norton speed disk
teamspeak server
even spyware has installed itself as a service on my computer.

my goal is to create a simple screensaver which can run as a service.