[英]System-wide setting in Windows 7 and 8 - Registry is no longer useful?
I want to track a setting system-wide on the target machine- it is a run time counter that keeps track of how many times my client runs my software. 我想跟踪目标机器上整个系统的设置-它是一个运行时计数器,用于跟踪客户端运行我的软件的次数。 I decided to put this value in the registry, but I really want to track how many times it is run for the whole system, not just for the current user account.
我决定将此值放在注册表中,但我真的想跟踪整个系统(而不只是当前用户帐户)运行该值的次数。
I would expect to use HKLM to track this at a machine level, but UAC doesn't like this nowdays. 我希望可以使用HKLM在计算机级别进行跟踪,但是UAC现在不喜欢这种情况。
Is there a correct way to read and write a setting that is machine-wide? 是否有正确的方法来读写机器范围内的设置?
HKLM
isn't for this type of use (since Windows XP at least). HKLM
不适用于这种类型的使用(至少从Windows XP开始)。
Use the %PROGRAMDATA%
folder instead (which you can also get via the WinAPI function SHGetKnownFolderPath
with FOLDERID_ProgramData
( SHGetFolderPath
with CSIDL_APPDATA
on Windows versions prior to Vista). It's specifically designed for application data that is global to all users of the machine. (On Windows 7, this is the C:\\ProgramData
folder by default.) Your application should create a directory beneath there and store the counter information in a file in that location instead. 请改用
%PROGRAMDATA%
文件夹(您也可以通过WinAPI函数SHGetKnownFolderPath
和FOLDERID_ProgramData
( SHGetFolderPath
和CSIDL_APPDATA
在Vista之前的Windows版本上获得)。它专门用于对计算机所有用户都是全局的应用程序数据。 Windows 7,默认情况下为C:\\ProgramData
文件夹。)您的应用程序应在该目录下创建一个目录,并将计数器信息存储在该位置的文件中。
(It also means you don't have to defeat the purpose of UAC by allowing public write access to the registry in inappropriate locations.) (这也意味着您不必通过允许在不适当的位置公开访问注册表来破坏UAC的目的。)
From Environment.SpecialFolder Enumeration : 从Environment.SpecialFolder枚举 :
CommonApplicationData The directory that serves as a common repository for application-specific data that is used by all users. CommonApplicationData该目录充当所有用户使用的特定于应用程序的数据的公共存储库。
Have a "CommonApplicationData\\Your Company Name\\Your Product Name" folder created in your setup program and change the ACL for the folder to allow limited user full control permissions (the inherited permission is read only for limited users). 在安装程序中创建一个“ CommonApplicationData \\您的公司名称\\您的产品名称”文件夹,并更改该文件夹的ACL以允许受限用户的完全控制权限(继承的权限仅对受限用户只读)。 You can do this via the LockPermissions MSI table, or if your setup program does not support LockPermissions, create a custom action to change the ACL.
您可以通过LockPermissions MSI表执行此操作,或者如果安装程序不支持LockPermissions,则创建一个自定义操作来更改ACL。
You also need to handle potential edit conflicts created by fast user switching. 您还需要处理由快速用户切换造成的潜在编辑冲突。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.