Valhalla Legends Forums Archive | C/C++ Programming | Running C/C++ Applications as a Windows NT/2000/XP/2003 Service

AuthorMessageTime
Mephisto
After doing some minor research, I've concluded that you can't just make your C/C++ application run as a service on Windows. Is this true? And if so, how do you make your C/C++ do so? Do you have to make it a specific project (using VS.NET 2003)? Any links to information sites regarding this, or if someone could explain it to me on this thread would be appreciated...
August 6, 2004, 8:15 PM
Adron
Look for service.c and service.h from Microsoft for a good base to build a service from.


Otherwise you can just use the appropriate API calls.

In your service executable, you're supposed to call StartServiceCtrlDispatcher with the information on what services you can run from that executable. In the ServiceMain function for your service, you call RegisterServiceCtrlHandler to register for notifications about stopping, pausing, etc. You also call SetServiceStatus to tell Windows that you're up and running. Or stopping, or failed, or whatever has happened.


To get Windows to load your service, you need to register it, telling it what .exe file to run etc. You use OpenSCManager and CreateService to do that.


This is all well documented in the help files in vs.net.
August 6, 2004, 8:45 PM
St0rm.iD
srvany will do it!
August 7, 2004, 2:21 AM
Adron
[quote author=$t0rm link=board=30;threadid=8054;start=0#msg74436 date=1091845308]
srvany will do it!
[/quote]

That works, but if you can change the application to be a service, it will mostly be a much better solution. The stop button on a srvany service (when stopping the service, or when the computer is shutting down) kills the application. Much better if the application can save its things and shut down properly.
August 7, 2004, 7:15 PM

Search