What is the difference: LoadUserProfile -vs- RegOpenCurrentUser

冷暖自知 提交于 2019-12-03 00:44:44

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

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.

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?

Yes.

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

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?

Ditto.

JoshHetland

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

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)

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 StackOverflow 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.

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

The two functions are used in different situations.

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!