Windows 7 - 在哪里以及如何存储与机器用户无关的数据? [英] windows 7 - where and how can I store machine user independent data?

查看:41
本文介绍了Windows 7 - 在哪里以及如何存储与机器用户无关的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 XP 下运行的应用程序(32 位 c++),我需要适应它才能在 Windows 7 和 Vista 下运行.它需要在独立于用户的地方存储几十个字节的数据.在 XP 下,我将数据存储在注册表中的 HKEY_LOCAL_MACHINE\Software 下.当我在 Windows 7 上运行该应用程序时,注册表项是虚拟化的,每个用户都会获得一份单独的数据副本.

I have an app (32 bit c++) running under XP that I need to adapt to run under Windows 7 and Vista. It needs to store a few dozen bytes of data someplace independent of User. Under XP, I stored the data in the registry under HKEY_LOCAL_MACHINE\Software. When I run the app on Windows 7 the registry entries are virtual-ized and each user gets a separate copy of the data.

非虚拟化注册表似乎是数据的合乎逻辑的地方,但我不知道如何去做.我注意到有许多应用程序实际上在那里存储数据;他们是怎么做的?

The non-virtual-ized registry seems like a logical place for the data but I have no idea how to go about doing so. I note that there are a multitude of applications that actually store data there; how do they go about doing so?

我也愿意将数据存储在其他地方,是否有一些众所周知的全局存储库?我只需要一个小文件.

I'm also willing to store the data else where, is there is some well know global repository for it? A single small file is all I need.

我或多或少对整个权利/特权业务一无所知,因此非常感谢任何提示、指示等.

I'm more or less ignorant of the whole rights/privileges business so any hints, pointers, etc much appreciated.

推荐答案

Windows 7 的设计目标之一是隔离用户数据和应用程序.这是为了改善隐私、安全和定制.实际上,Win 7 中的标准用户无法更改其他用户的数据.

One of the design goals of Windows 7 is to isolate user data and applications. This is to improve privacy, security, and customization. In fact, standard users in Win 7 cannot change data of other users.

存储应用程序数据的标准位置由 System.Environment.SpecialFolder 枚举.请注意,并非所有文件夹都可供所有用户读取或写入.例如,CommonApplicationData 可供所有用户读取,但只能由具有适当策略的用户(如管理员)写入.

The standard places to store application data is returned by the System.Environment.SpecialFolder enumeration. Note that not all folders are readable or writable by all users. For example, CommonApplicationData is readable by all users, but only writable by those with an appropriate policy, like Admins.

如果您绝对必须拥有在用户之间共享的数据,则管理员或具有权限的人必须将其安装到共享位置.如果用户需要更新这些数据,他们应该将其复制到他们可以写入的位置,例如 ApplicationData,并更新他们自己的私有副本.其他用户无法更改此私人副本.除非您的应用程序无法正常运行,否则您不应将数据安装到共享位置.

If you absolutely must have data that is shared among users, an Admin or one with permission must install it to a shared location. If users need to update this data, they should copy it to a location they can write to, such as ApplicationData, and update their own private copies. This private copy cannot be changed by other users. You should not install data to shared locations unless your application won't work otherwise.

实际上,在 Win7 中,您应该将所有应用程序和数据安装到登录用户的应用程序和数据文件夹,而不是共享位置.如果多个用户安装该应用程序,每个用户将获得他们自己的应用程序和数据副本.这几乎总是你想要的.如果多个用户正在运行一个应用程序或游戏,您不希望一个用户改变其他所有人.如果多个用户确实需要相同的更改,请让每个用户在需要时更新他们的私人副本.如果一个用户的帐户被黑或变坏,您不希望它破坏其他所有人的应用程序和数据.

In fact, in Win7 you should install all applications and data to the logged-on user's application and data folders, not to shared locations. If multiple users install the application, each user will get their own copy of the application and data. This is almost always what you want. If multiple users are running an application or game, you do not want one user changing everyone else. If multiple users really do need the same change, let each user update their private copy when they need it. If one user's account is hacked or turns evil, you do not want it destroying everyone else's applications and data.

另请注意,在 Win7 中,用户可以远程登录机器,因此按用户存储特定于机器的数据(如屏幕分辨率或 IP 地址)并不是一个好主意.相反,每次您的应用运行时都要检查这一点.

Also be aware that in Win7, users can log on to a machine remotely, so it is not a good idea to store machine-specific data, like screen resolutions or IP addresses, by user. Instead, check this every time your app runs.

这篇关于Windows 7 - 在哪里以及如何存储与机器用户无关的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆