Home All Groups Group Topic Archive Search About

Settings for a windows service: where to store ?

Author
7 Oct 2005 9:34 AM
Craig HB
From a .net windows service, I was tryng to access the app.config file using
System.Configuration.ConfigurationSettings.AppSettings, but it didn't return
the settings.

Can you access the app.config file from a .net windows service? If you can,
where does the file need to be? If you can't, where is a good place to store
data (connection strings, file paths etc) that you would normally put in the
app.config file?

Thanks,
Craig

Author
7 Oct 2005 1:50 PM
Rob Schieber
Craig HB wrote:
> From a .net windows service, I was tryng to access the app.config file using
> System.Configuration.ConfigurationSettings.AppSettings, but it didn't return
> the settings.
>
> Can you access the app.config file from a .net windows service? If you can,
> where does the file need to be? If you can't, where is a good place to store
> data (connection strings, file paths etc) that you would normally put in the
> app.config file?
>
> Thanks,
> Craig

Craig

Try the placing your app.config file in your system directory e.g.
C:\Windows\System32\ .

--
Rob Schieber
Author
7 Oct 2005 3:04 PM
José Joye
By default the working directory is C:\Windows\System32\.
So what I will do is to redifine the working directory at startup of the
service

protected override void OnStart(string[] args)
{
  try
  {
    // Define working directory (For a service, this is set to System)
    Process pc = Process.GetCurrentProcess();
    Directory.SetCurrentDirectory
(pc.MainModule.FileName.Substring(0,pc.MainModule.FileName.LastIndexOf(@"\")
));
    ....

This will allow you to them place the exe.config file in the same directory
of the service file and all is ok


- José


Show quote
"Rob Schieber" <schie***@hotmail.com> wrote in message
news:OyPpPY0yFHA.2064@TK2MSFTNGP09.phx.gbl...
> Craig HB wrote:
> > From a .net windows service, I was tryng to access the app.config file
using
> > System.Configuration.ConfigurationSettings.AppSettings, but it didn't
return
> > the settings.
> >
> > Can you access the app.config file from a .net windows service? If you
can,
> > where does the file need to be? If you can't, where is a good place to
store
> > data (connection strings, file paths etc) that you would normally put in
the
> > app.config file?
> >
> > Thanks,
> > Craig
>
> Craig
>
> Try the placing your app.config file in your system directory e.g.
> C:\Windows\System32\ .
>
> --
> Rob Schieber
Author
7 Oct 2005 10:47 PM
john conwell
For any app, including windows services, the config file should be in the
same folder the assembly is located.  and the service assembly can reside
anywhere you want, as long as you dont move it after its registered as a
service. 

make sure your config file is named correctly.

appname.exe.config

so if your service is called myService.exe, then the config file will be
myService.exe.config and it should be in the same folder as the actual
executable.

Show quote
"Rob Schieber" wrote:

> Craig HB wrote:
> > From a .net windows service, I was tryng to access the app.config file using
> > System.Configuration.ConfigurationSettings.AppSettings, but it didn't return
> > the settings.
> >
> > Can you access the app.config file from a .net windows service? If you can,
> > where does the file need to be? If you can't, where is a good place to store
> > data (connection strings, file paths etc) that you would normally put in the
> > app.config file?
> >
> > Thanks,
> > Craig
>
> Craig
>
> Try the placing your app.config file in your system directory e.g.
> C:\Windows\System32\ .
>
> --
> Rob Schieber
>
Author
9 Oct 2005 1:01 PM
Craig HB
Thanks, John -- that worked

AddThis Social Bookmark Button