Access Denied when Reading/Writing to Program FIles

Deadly 提交于 2020-01-05 05:22:05

问题


I have a small program that is installed in a custom folder in the program files, but when I tried to read or write to files that are needed to operate, the program raises an Access Denied Exeption. How can I elevte the program, with the user's permission of course.


回答1:


I guess you're running under Vista? In Vista I don't think you're allowed to read/write to files under Program Files, you should put your data files in Documents and Settings instead.




回答2:


To resolve the Access denied exception while reading. Please specify the file access as read, that will resolve the access denied exception while reading

e.g. fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);



回答3:


You can do everything you need using the ClickOnce APIs. If you have multiple parts (e.g., more than one EXE) then you need to include them in your package.

The only scenario not supported (by ClickOnce) as far as I know are authenticating proxies.




回答4:


ClickOnce supports installing any number of executable files, although you may need to manually include them in the manifest definitions.

To be correct and play well within the restrictions of least user access (LUA) and user access controls (UAC) your application should not write to the program files folder at all except during installation. If you must do this, you should include a manifest file that indicates your application requires elevated privileges to run. (If you are running on Vista you can also set the compatability mode.)



来源:https://stackoverflow.com/questions/298187/access-denied-when-reading-writing-to-program-files

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