I am currently making my first attempts at creating a simple Windows Service using C# and .NET. I am at a point where the service does what it is supposed to do, but uses a lot of hard-coded values. I want to move these values to a separate configuration area - probably the Windows registry. I would like to provide my service with a kind of default configuration - if the settings / registry entries aren't present, create a set of default values and warn the user that the default values may need to be adjusted. However, I am unsure on when to perform this operation:
I could create the registry entries from the constructor of the
ServiceBase
descendant.I could create the entries within the installer I created following the tutorial (a subclass
System.Configuration.Install.Installer
).
I am unsure whether there are other options, what the pros and cons of these options are and whether there is a "correct" approach to perform this. I am even less sure if and where I should provide code to automatically remove the registry entries.