我的应用程序需要像大多数应用程序一样存储数据.该应用程序以前只在 XP 上使用,它会将数据存储在 Program Files
中.现在我们的客户正在迁移到 Windows 7,我必须对其进行升级,以便将数据存储在一个新文件夹中.我选择了 ApplicationData
文件夹,因为我认为完全不需要 UAC 就可以访问.
My application needs to, like most, store data. The application was previously used on XP only where it would store the data in Program Files
. Now that our customers are moving to Windows 7 I had to upgrade it so that it stored the data in a new folder. I opted for the ApplicationData
folder as I thought I would be allowed access without needing UAC at all.
现在在某些 Windows 7 机器上这很好,但在其他机器上访问该文件夹失败,可能是因为权限问题,但是当以管理员权限运行时,程序可以正常工作.
Now on some Windows 7 machines this is fine, but on others access to the folder fails, presumably because of permissions, but when ran with Administrator privelidges the program works fine.
我使用了错误的文件夹还是这些案例异常?无论哪种情况,这种事情的最佳做法是什么?
Am I using the wrong folder or are these cases outliers? In either case what is the best practice for this kind of thing?
我正在使用以下 C# SpecialFolder
来获取 AppData 文件夹位置.
I am using the following C# SpecialFolder
to get the AppData folder location.
System.Environment.SpecialFolder.ApplicationData
System.Environment.SpecialFolder.ApplicationData
是每个用户和漫游的.这听起来不像你想要的.您似乎需要机器范围的设置,因此应该使用 System.Environment.SpecialFolder.CommonApplicationData
.
System.Environment.SpecialFolder.ApplicationData
is per-user and roams. That doesn't sound like what you want. You appear to want machine wide settings and so should use System.Environment.SpecialFolder.CommonApplicationData
.
因为 CommonApplicationData
是所有用户共享的,所以默认的访问控制是有限的.默认情况下,标准用户无法在此位置写入.推荐的做法是在安装时创建 CommonApplicationData
的子文件夹,并为其分配适当的许可访问控制设置.
Because CommonApplicationData
is shared between all users, the default access control is limited. By default standard users cannot write in this location. The recommended practise is to create a sub-folder of CommonApplicationData
at installation time and assign it suitably permissive access control settings.
这篇关于在 Windows 7 和 Vista 中存储应用程序数据的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!