Lightbringer
Lightbringer

Reputation: 819

Where is the user.config of a .NET service located?

I'am installing a .NET based Windows service using installutil.exe. (.NET 4.0) This service includes a ServiceName.exe.config file. This file is stored in the same directory as the .exe file itself. But it seems that this file only holds the default values (like in "standard" .NET Applications). Changing a setting during runtime of the service doesn't take effect in the ServiceName.exe.config located in the installation path (as answers to http://stackoverflow.com/questions/17154936/net-service-config-file-locationother similar questions suggest). Looking in C:\Windows\Users\"Username"\AppData\Local\ also does not bring success.

Changing a setting is working, i checked that by writing some setting values into a log file. The only question is, in which file and in which location are the values stored?

EDIT:

The config-file looks like this.

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="MeLoQDASExportService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="MeLoQDASExportService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
        </sectionGroup>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
    </startup>
    <applicationSettings>
        ...
    </applicationSettings>
    <userSettings>
        <MeLoQDASExportService.Properties.Settings>
            <setting name="logName" serializeAs="String">
                <value>ExportLog.txt</value>
            </setting>
            <setting name="lastExport" serializeAs="String">
                <value>1990-01-01</value>
            </setting>
        </MeLoQDASExportService.Properties.Settings>
    </userSettings>
</configuration> 

This is the file in the folder of the installed service. It still contains the initial values, but an output of the values from the service into a text file shows me the actual values (e.g. the date of the current day for "lastExport")

Upvotes: 4

Views: 2284

Answers (2)

mnaoumov
mnaoumov

Reputation: 2227

I've just found using Process Monitor

c:\Windows\SysWOW64\config\systemprofile\AppData\

Upvotes: 1

Roshan Bhuran
Roshan Bhuran

Reputation: 59

Try System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel level) http://msdn2.microsoft.com/en-us/library/ms134265.aspx

passing in ConfigurationUserLevel.PerUserRoamingAndLocal (or also try PerUserRoaming). Then on the returned Configuration object, get the FilePath property.

Upvotes: 0

Related Questions