开发者

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

I want to 开发者_JAVA技巧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?


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.


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.


You need to use elevation in order to modify those files, due to User Access Control. Take a look at this MSDN article for more details: MSDN article about UAC

If you are not sure how to do this in C#, here is an article: Article about requesting elevation in C#


It's a security option turned on by default in windows 7 namely UAC (user Account Control). You should change your design (write somewhere else) or turn off UAC from control panel\User Accounts.


I have run into this same problem, but using the Inno Setup Installer, I have a parameter named "Permissions" where I set the value "users-full" to create a file in my application folder into the common application data with full control for all users of that file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜