问题
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