在 Windows 7 和 Vista 中存储应用程序数据的位置

Where to store Application Data in Windows 7 and Vista(在 Windows 7 和 Vista 中存储应用程序数据的位置)
本文介绍了在 Windows 7 和 Vista 中存储应用程序数据的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要像大多数应用程序一样存储数据.该应用程序以前只在 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 中存储应用程序数据的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)