-1

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.

vwegert
  • 18,371
  • 3
  • 37
  • 55

1 Answers1

1

If you're using the register, you should let the installer to create the default key/values pairs, and let the uninstaller delete them.

Another way is to use the app config file, which is more simple then dealing with registry, See this posts: Simplest way to have a configuration file in a Windows Forms C# Application

Community
  • 1
  • 1
Matt
  • 6,010
  • 25
  • 36
  • I need my service to be configurable by the admin who installs it, not at design/compilation time. I'm not sure whether the app config file is the way to go...? – vwegert Feb 20 '14 at 08:08
  • sure, you can do it with config file – Matt Feb 20 '14 at 13:26