I have a problem in understanding the relationship between services and registry.
I have the task of taking my windows C++ program and transform it from simple application to a service.
I read that I need to produce some more functions as: start stop resume install.
The problem is:
-
Why I need the regisrty ?
-
how I enter the new program ?
-
Beside those method what I need to do with the registry? how I enter inside it ?
-
Do I need to write a script for entering the service ?
I read but I just didn’t understand, any answear and or some good links to explanation will be appreciated.
Thanks,
I’m not aware of any documented relationship between services and the registry. Services can use the registry to store their settings, just like any other application, but they’re not required to.
Formally, you don’t need the registry. You simply need to install the service using the relevant API functions. As part of their implementation, the API functions create registry entries that the OS uses later to know when and how to start your service, but I don’t think those keys are documented with any expectation that developers would modify them manually, so don’t worry about them.
If your program uses the registry to store settings, though, you’ll need to understand what account your service runs as, because that affects what areas of the registry your program has access to.
Install your service by calling
CreateService. Do that in your program’s installer. You can also make your service install itself when it detects itself being run with a certain command-line switch, such as-i. To uninstall your service, callOpenServiceand thenDeleteService. In either case, you’ll need to callOpenSCManagerfirst. See MSDN for more on how to call those functions.Alternatively, you can use the
sccommand to create and delete your service.As I mentioned above, you don’t need to do anything with the registry. Just install and uninstall your service with the API and let the OS take care of the rest.
You don’t need to write any scripts to start your service. The OS already knows how to start it (because it’s installed). If your service is something that users would want to start and stop frequently, then rather than use the service control panel then they can use the
netorsccommands.