I write a C# application that needs to write in a file that is in the program files folder in Windows Drive. and for this, I must run my app as administrator otherwise an error happened. I want to run my app in normal form ( not as administrator ). Is there a solution?
Asked
Active
Viewed 3,344 times
2
-
Already answered. Check http://stackoverflow.com/questions/10453299/deactivate-uac-in-windows-7-for-a-specific-program – OriolBG Jul 23 '13 at 07:56
-
Why are you writing files in the program files folder? – Scott Chamberlain Jul 23 '13 at 08:05
-
@Scott Chamberlain: I need to write in a file that there is in the program files folder, this file copy into program files folder when I install my app, and I can not change place of it :( – Javad Yousefi Jul 23 '13 at 08:14
-
Then you must use option 2 or option 3 from my answer. – Scott Chamberlain Jul 23 '13 at 08:17
2 Answers
3
You have a few options (in order of preferred option)
- Don't write to Program Files! You should not be modifying files after the program is installed. If you need files that are writable and common to all users you should be writing to the folder returned by
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
- Run the program as an administrator always by adding a manifest file (see Ehsan's answer)
- Change the folder permissions on the folder you are trying to access so members of the
Users
group can write to the folder instead of only being able to read it.

Scott Chamberlain
- 124,994
- 33
- 282
- 431
2
Add an application manifest file from project-->Add File-->Manifest and change this line as
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Ehsan
- 31,833
- 6
- 56
- 65