Hello Gary,
From your post, my understanding on the issue is that you want to know a
practical way to store app settings in a windows service.
Actually, you can add a config file, commonly named as "App.config" into
your windows service project. The following is a snippet of the config
file. You may add what you want, including appSetting and
connectionStrings. After the build, the config file will be named as
"xxx.exe.config".
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings></appSettings>
<connectionStrings></connectionStrings>
</configuration>
You may use the following steps to add a config file in your windows
service project.
1. Right click the project, select Add->New Item¡
2. Select the "Application Configuration File" in the "Add New Item" dialog
Commonly, the configuration file exists in the same folder with windows
service file. Of course, you may put the configuration file to other
folder. In this scenario, you must use the method
"ConfigurationManager.OpenMappedExeConfiguration" to tell the windows
service where its configuration is located. You may take the following
codes as reference:
static void Main(string[] args)
{
//other code
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = args[0];
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(
fileMap, ConfigurationUserLevel.None);
//other code
}
More examples for your references:
http://www.aspfree.com/c/a/C-Sharp/Creating-a-Windows-Service-with-C-sharp-c
oncluded/
http://www.15seconds.com/issue/040624.htm
Regarding the built-in attributes of services (e.g. not interacting with a
user), their setting information is stored in the registry. You may find
these information in the following subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Please let me know the information above so that I can provide further
assistance on this problem. I am looking forward to your reply.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.