有什么区别:LoadUserProfile -vs- RegOpenCurrentUser

时间:2021-10-31 15:41:38

These two APIs are very similar but it is unclear what the differences are and when each should be used (Except that LoadUserProfile is specified for use with CreateProcessAsUser which I am not using. I am simply impersonating for hive accesss).

这两个API非常相似,但不清楚区别是什么以及何时应该使用它们(除了指定LoadUserProfile与我没有使用的CreateProcessAsUser一起使用。我只是模仿hive访问)。

LoadUserProfile http://msdn.microsoft.com/en-us/library/bb762281(VS.85).aspx

RegOpenCurrentUser http://msdn.microsoft.com/en-us/library/ms724894(VS.85).aspx

According to the Services & the Registry article: http://msdn.microsoft.com/en-us/library/ms685145(VS.85).aspx we should use RegOpenCurrentUser when impersonating.

根据服务和注册表的文章:http://msdn.microsoft.com/en-us/library/ms685145(VS.85).aspx我们应该在模仿时使用RegOpenCurrentUser。

But what does/should RegOpenCurrentUser do if the user profile is roaming - should it load it?

但是,如果用户配置文件正在漫游,那么RegOpenCurrentUser应该做什么/应该加载它?

As far as I can tell from these docs, both APIs provide a handle to the HKEY_CURRENT_USER for the user the thread is impersonating. Therefore, they both "load" the hive i.e. lock it as a database file and give a handle to it for registry APIs.

据我所知,这两个API为线程模拟的用户提供了HKEY_CURRENT_USER的句柄。因此,它们都“加载”配置单元,即将其作为数据库文件锁定,并为注册表API提供句柄。

It might seem that LoadUserProfile loads the user profile in the same way as the User does when he/she logs on, whereas RegOpenCurrentUser does not - is this correct? What is the fundamental difference (if any) in how these two APIs mount the hive?

似乎LoadUserProfile以与用户登录时相同的方式加载用户配置文件,而RegOpenCurrentUser则不是 - 这是正确的吗?这两个API如何安装蜂巢的根本区别(如果有的话)是什么?

What are the implications and differences (if any) between what happens IF

IF之间发生的影响和差异(如果有的话)是什么?

  1. A user logs-on or logs-off while each of these impersonated handles is already in use?

    用户登录或注销,而这些模拟句柄中的每一个都已被使用?

  2. A user is already logged-on when each matching close function (RegCloseKey and UnloadUserProfile) is called?

    当调用每个匹配的关闭函数(RegCloseKey和UnloadUserProfile)时,用户已经登录?

3 个解决方案

#1


But what does/should RegOpenCurrentUser do if the user profile is roaming - should it load it?

但是,如果用户配置文件正在漫游,那么RegOpenCurrentUser应该做什么/应该加载它?

It doesn't load the profile. Think about it this way: If it did, you'd have to somehow call UnloadUserProfile() when finished with the handle to HKEY_CURRENT_USER.

它不会加载配置文件。以这种方式思考:如果确实如此,那么在完成HKEY_CURRENT_USER的句柄时,你必须以某种方式调用UnloadUserProfile()。

It might seem that LoadUserProfile loads the user profile in the same way as the User does when he/she logs on, whereas RegOpenCurrentUser does not - is this correct?

似乎LoadUserProfile以与用户登录时相同的方式加载用户配置文件,而RegOpenCurrentUser则不是 - 这是正确的吗?

Yes.

What is the fundamental difference (if any) in how these two APIs mount the hive?

这两个API如何安装蜂巢的根本区别(如果有的话)是什么?

None.

What are the implications and differences (if any) between what happens IF A user logs-on or logs-off while each of these impersonated handles is already in use?

如果用户登录或注销,而这些模拟句柄中的每一个都已被使用,会发生什么影响和差异(如果有的话)?

They'll get their own handle (to the same key) that's opened and closed.

他们将获得自己的手柄(相同的钥匙)打开和关闭。

A user is already logged-on when each matching close function (RegCloseKey and UnloadUserProfile) is called?

当调用每个匹配的关闭函数(RegCloseKey和UnloadUserProfile)时,用户已经登录?

Ditto.

#2


As I am currently trying to accomplish the same thing you are I thought I would chime in with what I've found over the last few days.

因为我现在正在努力完成同样的事情,我想我会在最近几天找到我所发现的东西。

I'm working in a Windows XP sp3 environment and trying to achieve impersonation with CurrentUser registry access in two different scenarios

我正在Windows XP sp3环境中工作,并试图在两种不同的场景中使用CurrentUser注册表访问来模拟

If you come across anything useful I would be greatly appreciative if you share your experience. My stack overflow question can be found here

如果您遇到任何有用的东西,如果您分享您的经验,我将非常感激。我的堆栈溢出问题可以在这里找到

Administrator > Limited User & Limited User > Administrator

管理员>受限用户和受限用户>管理员

What I've noticed so far is (in Windows XP sp3)

到目前为止我注意到的是(在Windows XP sp3中)

LoadUserProfile():

Only works when the impersonating user has SeRestoreName and SeBackupName privileges enabled among others (simply enabling these two for the limited user in question was not enough as it still failed with an access denied error - See my * question for more details on that). The only way I'm able to successfully call LoadUserProfile() so far is to do so by an Administrator account before starting impersonation.

仅当模拟用户启用了SeRestoreName和SeBackupName权限时才起作用(仅为有限用户启用这两个权限是不够的,因为它仍然因访问被拒绝错误而失败 - 有关详细信息,请参阅我的*问题)。到目前为止,我能够成功调用LoadUserProfile()的唯一方法是在开始模拟之前通过管理员帐户执行此操作。

RegOpenCurrentUser():

Only works "properly" when the user's profile is already loaded, In every attempt I've made so far I'm only able to get a handle to the S-1-5-18 hive unless the users hive is loaded and accessible under HKEY_USERS already

只有当用户的个人资料已经加载时才能“正常”工作。在我迄今为止所做的每一次尝试中,我只能获得S-1-5-18配置单元的句柄,除非用户配置单元已加载并且可以访问HKEY_USERS已经

#3


The two functions are used in different situations.

这两个功能用于不同的情况。

LoadUserProfile is suitable if the user profile is not already loaded.

如果尚未加载用户配置文件,则LoadUserProfile是合适的。

RegOpenCurrentUser is suitable if the user profile is already loaded, i.e., if you want to access the registry hive for a user who is already interactively logged on.

如果已加载用户配置文件,即,如果要为已经交互式登录的用户访问注册表配置单元,则RegOpenCurrentUser是合适的。

Note that LoadUserProfile is usually called without impersonation (because you must have admin privilege to use it) but RegOpenCurrentUser has to be called with impersonation.

请注意,LoadUserProfile通常在没有模拟的情况下调用(因为您必须具有管理员权限才能使用它),但必须通过模拟调用RegOpenCurrentUser。

#1


But what does/should RegOpenCurrentUser do if the user profile is roaming - should it load it?

但是,如果用户配置文件正在漫游,那么RegOpenCurrentUser应该做什么/应该加载它?

It doesn't load the profile. Think about it this way: If it did, you'd have to somehow call UnloadUserProfile() when finished with the handle to HKEY_CURRENT_USER.

它不会加载配置文件。以这种方式思考:如果确实如此,那么在完成HKEY_CURRENT_USER的句柄时,你必须以某种方式调用UnloadUserProfile()。

It might seem that LoadUserProfile loads the user profile in the same way as the User does when he/she logs on, whereas RegOpenCurrentUser does not - is this correct?

似乎LoadUserProfile以与用户登录时相同的方式加载用户配置文件,而RegOpenCurrentUser则不是 - 这是正确的吗?

Yes.

What is the fundamental difference (if any) in how these two APIs mount the hive?

这两个API如何安装蜂巢的根本区别(如果有的话)是什么?

None.

What are the implications and differences (if any) between what happens IF A user logs-on or logs-off while each of these impersonated handles is already in use?

如果用户登录或注销,而这些模拟句柄中的每一个都已被使用,会发生什么影响和差异(如果有的话)?

They'll get their own handle (to the same key) that's opened and closed.

他们将获得自己的手柄(相同的钥匙)打开和关闭。

A user is already logged-on when each matching close function (RegCloseKey and UnloadUserProfile) is called?

当调用每个匹配的关闭函数(RegCloseKey和UnloadUserProfile)时,用户已经登录?

Ditto.

#2


As I am currently trying to accomplish the same thing you are I thought I would chime in with what I've found over the last few days.

因为我现在正在努力完成同样的事情,我想我会在最近几天找到我所发现的东西。

I'm working in a Windows XP sp3 environment and trying to achieve impersonation with CurrentUser registry access in two different scenarios

我正在Windows XP sp3环境中工作,并试图在两种不同的场景中使用CurrentUser注册表访问来模拟

If you come across anything useful I would be greatly appreciative if you share your experience. My stack overflow question can be found here

如果您遇到任何有用的东西,如果您分享您的经验,我将非常感激。我的堆栈溢出问题可以在这里找到

Administrator > Limited User & Limited User > Administrator

管理员>受限用户和受限用户>管理员

What I've noticed so far is (in Windows XP sp3)

到目前为止我注意到的是(在Windows XP sp3中)

LoadUserProfile():

Only works when the impersonating user has SeRestoreName and SeBackupName privileges enabled among others (simply enabling these two for the limited user in question was not enough as it still failed with an access denied error - See my * question for more details on that). The only way I'm able to successfully call LoadUserProfile() so far is to do so by an Administrator account before starting impersonation.

仅当模拟用户启用了SeRestoreName和SeBackupName权限时才起作用(仅为有限用户启用这两个权限是不够的,因为它仍然因访问被拒绝错误而失败 - 有关详细信息,请参阅我的*问题)。到目前为止,我能够成功调用LoadUserProfile()的唯一方法是在开始模拟之前通过管理员帐户执行此操作。

RegOpenCurrentUser():

Only works "properly" when the user's profile is already loaded, In every attempt I've made so far I'm only able to get a handle to the S-1-5-18 hive unless the users hive is loaded and accessible under HKEY_USERS already

只有当用户的个人资料已经加载时才能“正常”工作。在我迄今为止所做的每一次尝试中,我只能获得S-1-5-18配置单元的句柄,除非用户配置单元已加载并且可以访问HKEY_USERS已经

#3


The two functions are used in different situations.

这两个功能用于不同的情况。

LoadUserProfile is suitable if the user profile is not already loaded.

如果尚未加载用户配置文件,则LoadUserProfile是合适的。

RegOpenCurrentUser is suitable if the user profile is already loaded, i.e., if you want to access the registry hive for a user who is already interactively logged on.

如果已加载用户配置文件,即,如果要为已经交互式登录的用户访问注册表配置单元,则RegOpenCurrentUser是合适的。

Note that LoadUserProfile is usually called without impersonation (because you must have admin privilege to use it) but RegOpenCurrentUser has to be called with impersonation.

请注意,LoadUserProfile通常在没有模拟的情况下调用(因为您必须具有管理员权限才能使用它),但必须通过模拟调用RegOpenCurrentUser。