Link to home
Avatar of StarDusterII
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?
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of StarDusterII
StarDusterII

ASKER

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
can you share your final solution?