Read Machine.Config

  • Thread starter Brian Patterson
  • 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");
 
R

Richard Grimes [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

config file 1
Renaming a directory 4
Listview and threaded filecopy 3
Configuration Error 3
machine.config problem 2
Nested iterator problem 2
Error loading XML file 3
read machine.config 1

Top