Avatar of StarDusterII
 asked on

C# access denied error reading c:\windows\system32\inetsrv\config

I'm trying to read the c:\windows\system32\inetsrv\config\applicationHost.config file with a C# program and getting the access denied error.  How do I give the program permission to read that file?
C#Windows OSWindows Server 2008

Avatar of undefined
Last Comment
Éric Moreau

8/22/2022 - Mon
Éric Moreau

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Took a quick look at these and they seem to be deailing with accessing files over a network.  I'm just trying to open a file for reading on the local computer.  Impersonation looks like overkill... Isn't there anything easier?  I have a VB6 program that reads the file with no problem.

After much searching and a little trial and error, I finally got this to work with the following:

IntPtr tokenHandle = new IntPtr(0);
WindowsImpersonationContext impersonatedUser;

tokenHandle = IntPtr.Zero;
bool returnValue =  LogonUser(userName,userDomain,userPassword,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,ref tokenHandle);

WindowsIdentity newId = new WindowsIdentity(tokenHandle);
impersonatedUser = newId.Impersonate();

There was nothing in the expert's post that helped other than the word "impersonation".   I spent hours searching for the final solution
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Éric Moreau

can you share your final solution?