gpt4 book ai didi

Windows:如何找到特定计算机上每个用户的 LocalAppData 目录?

转载 作者:可可西里 更新时间:2023-11-01 11:41:27 26 4
gpt4 key购买 nike

首先,一些背景:

我们的产品需要通过在 NOTES.INI 文件中添加或更新一行来与 Lotus Notes 客户端集成。

如果我们正在处理 Notes 的单用户安装,我们不会遇到问题(即如果机器上有多个 Windows 用户,他们都将使用相同的 Notes 配置)。在这种情况下,Notes 安装目录中只有一个 NOTES.INI 文件。

但是,在 Notes 的多用户安装下(每个 Windows 用户都有自己的 Notes 配置),每个用户都有自己的 NOTES.INI 文件存储在用户的 LocalAppData 目录中 - 例如C:\Documents and Settings\用户名\Local Settings\Application Data\Lotus\Notes.

问题来了:如果我们的产品安装在多用户 Notes 客户端安装的机器上,我们需要能够更新该机器上每个用户的配置文件中的 NOTES.INI 文件。

我们可以通过在用户登录时运行一个程序来做到这一点,该程序检查该用户的 NOTES.INI 文件是否已更新,如果没有,则更新它。但是,我们应用程序的卸载过程需要能够为机器上的所有用户撤销这些修改。

因此问题来了:假设我们的代码以本地管理员权限运行,是否有某种方法可以遍历每个用户的配置文件并找到他们的 LocalAppData 目录,以便我们进行必要的更改?

非常感谢任何建议:-)

编辑 2009-03-25 16:52 GMT:
看起来我有一个可能的方法(感谢 Martin C):

    For each subkey of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList:      If it's a "real" user (determined somehow):        Remember the subkey name - that's the user's SID        Read the ProfileImagePath value        If the user's Registry hive is not already loaded (i.e. there is no subkey of HKEY_USERS with the appropriate SID):          Enable the SE_BACKUP_NAME and SE_RESTORE_NAME privileges          Load the hive from ProfileImagePath\NtUser.dat using RegLoadKey        Try to find the user's LocalAppData folder using each of the following Registry keys in turn:          HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders          HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders          HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders          HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders        Expand environment variables in the resulting path if necessary (presumably just expanding %USERPROFILE% to the ProfileImagePath we got earlier)        Use the path to find the user's NOTES.INI file and make the appropriate changes        If we had to load the hive:          Unload the hive using RegUnLoadKey

我或许可以将其编码,但它似乎有点脆弱,而且它可能有多种出错方式。谁有更“官方”的方法?

最佳答案

可以枚举的子键

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

每个子项都包含“ProfileImagePath”,它将指向配置文件的基本路径。根据操作系统版本和语言设置,您可以确定 LocalAppData 的位置(注意,它是语言相关的!)。

编辑: 更进一步的可能起点是

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

不幸的是,这可能因用户而异,而 HKEY_USERS 仅包含已加载配置文件的用户的 key 。您可以尝试是否可以以某种方式加载配置文件(如果用户注册表尚未加载到 HKEY_USERS,也许可以以某种方式附加用户注册表?)。

关于Windows:如何找到特定计算机上每个用户的 LocalAppData 目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/681572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com