Error occurred loading a configuration file: Access to path c:\Program Files (x86)\… denied

六眼飞鱼酱① 提交于 2019-12-07 04:56:29

问题


I have an application which I deploy using a setup program in Visual Studio 2010 on Windows 7. The program deploys and runs fine on Windows 7 and XP, but when I deploy it on a Windows 8 system I get errors about access to a configuration file.

The program gets installed in c:\Program Files (x86)[Company Name][App Name]\ and the file being referenced is a temp file with a name that looks machine generated by Windows GetTempFile, e.g. x4q0toqw.tmp. which does not exist in this folder and then there is a reference to the exe config file (myapp.exe.config, which does exist)

If I build and run the code on the Windows 8 system it installs and runs fine, I don't get the error, but then if I deploy the Window 8 compiled app on Windows 7 I get the same errors about access to the configuration file. Both machines are 64-bit but generate a 32-bit application.

I don't plan on releasing two binaries. Can anyone tell me what is going on? I'm in the process of trying to setup JIT debugging to that I can attach to the exe when it throws exceptions, since debugging it natively doesn't help me as I don't get the exceptions.

Thanks,

Gary

This is on two different machines, but I login to the same domain as the same user on both, and am an administrator.


回答1:


Maybe your application is rewriting your app config during the load and this will cause the system to question the access grants... if so, may be you can change the properties of your application (the installed one) to have administrator rights... This will give your application to automatically have the right to programatically edit the app config.

OR... you can just forget about the app config rewriting and put everything in the default app config script. but this will expose your application database security...




回答2:


I had the same error. This is because the temp file gets created in C:\Program Files (x86)\[Company Name]\[App Name] folder and the normal Users (PC Name\Users) don't have the permission to modify this folder. As soon as I added modify permission, it started working fine.




回答3:


I resolved a very similar problem in Visual Studio 2010 on Win 7 by elevating the account privileges that my service ran under. See step 9 here:

Set the Account property to LocalSystem.

When my serviceProcessInstaller1 ran under LocalService account I got an error like yours. But changing the account to LocalSystem fixed this issue. My installed service was then able to write to its C:\Program Files (x86)\[Company Name]\[App Name]\[App Name].exe.Config file. This was even though the install for Just me checkbox was checked when I ran the service's setup program.

Bear in mind the remarks here though:

The LocalSystem value defines a highly privileged account, but most services do not require such an elevated privilege level.



来源:https://stackoverflow.com/questions/13344921/error-occurred-loading-a-configuration-file-access-to-path-c-program-files-x8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!