Read Machine.Config

  • Thread starter Thread starter Brian Patterson
  • Start date Start date
B

Brian Patterson

Hi -
I'm trying to manually read and parse Machine.Config. When I try this I
recieve the following error:
Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\" is
denied.

I am doing this by first getting the directory location of the framework and
passing it to a DirectoryInfo object. I can then use this object to move to
the Config folder. I suspect I only need to demand a permission in my code
but I'm not quite sure how to go about it. Unfortunately - using the built
in .NET methods to read .config files won't work for what I am doing so
accessing machine.config from my C# code is a must. Thanks!

Brian

---------<snip>---------

DirectoryInfo di = new
DirectoryInfo(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory());

di.MoveTo("CONFIG");
 
Brian said:
Hi -
I'm trying to manually read and parse Machine.Config. When I try
this I recieve the following error:
Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\" is
denied.

I am doing this by first getting the directory location of the
framework and passing it to a DirectoryInfo object. I can then use this
object to
move to the Config folder. I suspect I only need to demand a permission
in
my code but I'm not quite sure how to go about it. Unfortunately - using
the
built in .NET methods to read .config files won't work for what I am doing
so accessing machine.config from my C# code is a must. Thanks!

Basically, you're not intended to do this. Instead the expected mechanism is
to use ConfigurationSettings.GetConfig, but some sections will be excluded
from your access, and anyway the application config settings will override
any machine settings.

If you really do need access to machine.conf as a text file then you should
get the administrator to change the ACLs on the file (and/or folder).
However, there's a reason why those ACLs are applied and hence its not
always a good idea to change them.

So that lead to the question, why do you want to have direct access to
machine.config?

Richard
 
Back
Top