Self-starting configurable service | ||
Step 2. Saving configuration data into registry | ||
The code below needs some comments. The first is the changes of CreateNewService method. As you see all data from the ini file are duplicated and stored in registry. Due to command line check (SvComFindCommand calls in the program body) the CreateNewService method is called on service installation only. After the service s installed the ini file can be modified or even deleted and it will not damage our service configuration. Now when the configuration data are stored in the registry it is this data should be used when the service executes. So if the SvComFindCommand do not detects the /install switch in the command line then it means that the configuration data should be retriever from registry not from the ini file. The CreateOldServices call does it.
And one more thing: our application must not support the /reinstall switch. This switch assumes that uninstallation of existing service and its installation will be done in the Application.Run call. But we can't change the number of services and their names when this call is done so it makes impossible to modify the number of services or their names with /reinstall switch. So we simply disable this switch. Well, now our example is ready for tests. You can change the number of services, modify their names and display names, you can install, uninstall, run and stop them. Of course you can add any other configuration parameter to your service. Create your own configurable service, it is easy, isn't it? The source code of this step is available here (zip, 2.75kb). |
||
<< | Index | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | >> | ||
Add your comment | Read comments |
© 1998-2001
Alexey Dynnikov |