6

Windows Service Configuration File

 3 years ago
source link: https://www.codesd.com/item/windows-service-configuration-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Windows Service Configuration File

advertisements

I'm currently developing a basic windows service with a configuration file (servicename.exe.config), the default configuration file you access in a Visual Studio project properties. This service installs and runs correctly, however I am unable to find the configuration file of the installed service.

Read/Write code snippet:

/// <summary>
/// An idle period between sending warning emails to avoid spamming
/// </summary>
public static short WarningEmailIdleMin
{
    get
    {
        return Properties.Settings.Default.WarningEmailIdleMin;
    }
    set
    {
        Properties.Settings.Default.WarningEmailIdleMin = value;
        Properties.Settings.Default.Save();
    }
}

Project settings image:

aCkJI.png
  • The service is running under the local system account
  • When stopping the service, changing a setting in the servicename.exe.config (next to the executable) and starting the service does not change the setting (proving its not pulling the settings from this config file)
  • When altering a setting in the service code, stopping and starting the service, the setting has the updated value from the previous run (proving it is being saved somewhere)
  • AppDomain.CurrentDomain.SetupInformation.ConfigurationFile points to the above config file

I have looked in the sub-directories of AppData in the default and public user accounts, I have also looked in C:\Windows\system32\config\systemprofile\AppData\

Any help would be appreciated :)

EDIT: Added code snippet of save/read


You are using user settings. These settings are not stored in servicename.exe.config next to the executable. I found this article at MSDN. It describes where user.config is stored and how to get the file path of that config.

Personally I don't think that using user settings is a good choice for windows service which by default runs under local system account (if not set differently). I would suggest to use a local file database (i.e. sqlite or Sqlserver CE etc.) for these settings.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK