Jonathan Camilleri
Jonathan Camilleri

Reputation: 23

Access Denied when Reading/Writing to Program FIles

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.

Upvotes: 1

Views: 4257

Answers (4)

Marimuthu
Marimuthu

Reputation: 11

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);

Upvotes: 1

Scott Dorman
Scott Dorman

Reputation: 42526

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.)

Upvotes: 0

Philipp Schmid
Philipp Schmid

Reputation: 5828

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.

Upvotes: 0

Ulf Lindback
Ulf Lindback

Reputation: 14190

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.

Upvotes: 1

Related Questions