Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 7 doesn't allow me edit files in Common Application Data folder

Tags:

c#

windows

uac

I want to store some files and edit them for my software in common Application Data under Windows 7.

I do not know why Windows 7 doesn't allow my software to change files unless I run them as administrator.

Where can I store my files, so it won't require admin permission?

like image 291
Ata Avatar asked Oct 15 '10 19:10

Ata


2 Answers

You should store your application data in a subfolder under Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); . Note that this folder is user-specific.

Non-Admin users do not have permission to write to the CommonApplicationData folder, because that folder does not belong to specific users.

Note that you can also store your settings by using the Settings Class. To do so, add New Item to your project, pick "Settings File". This is appropriate for basic settings like strings and numbers.

like image 190
Brian Avatar answered Sep 28 '22 09:09

Brian


Some folders are restricted starting in windows 7, these folders should not be touched unless you are installing, uninstalling, or patching. Please see my answer that you accepted from earlier today it is the exact same case.

If you have multiple aplications that need to edit the same files they should be stored in

Environment.GetFolderPath( Environment.SpecialFolder.CommonApplicationData)

System.Environment.SpecialFolder.CommonProgramFiles (the folder I think you are trying to write to) is read only unless you are elevated.

read this article from the MSDN it explains where you should be saving data and how do use the various folders correctly. My solution is the first one on his list, to summarize:

You need to create a folder while you are installing the program in the CommonApplicationData folder then set permissions on that new folder so it will have write access from the users group.

like image 35
Scott Chamberlain Avatar answered Sep 28 '22 08:09

Scott Chamberlain