What is the difference: LoadUserProfile -vs- RegOpenCurrentUser

The 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 do not use. I just impersonate access to the bushes).

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 article “Services and the registry”: http://msdn.microsoft.com/en-us/library/ms685145(VS.85).aspx we must use RegOpenCurrentUser for impersonation.

But what to do / should RegOpenCurrentUser do, if the user profile is in roaming - should he download it?

As far as I can tell from these docs, both APIs provide the HKEY_CURRENT_USER handle for the user, representing the stream. Therefore, they both “load” the hive, that is, lock it as a database file and provide it with a descriptor for registry APIs.

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

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

  • Is the user logging in or logging out when each of these issued pens is already in use?

  • Has the user already logged in when each corresponding close function (RegCloseKey and UnloadUserProfile) is called?

+4
source share
3 answers

But what to do / should RegOpenCurrentUser do, if the user profile is in roaming - should he download it?

It does not load a profile. Think of it this way: if so, you need to somehow call UnloadUserProfile() when you're done with the HKEY_CURRENT_USER handle.

It may seem that LoadUserProfile loads the user profile in the same way as the user does when he / she logs in, while RegOpenCurrentUser does not work - is this correct?

Yes.

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

Is absent.

What are the consequences and differences (if any) between what happens IF the user logs in or logs out while each of these issued pens is already in use?

They will receive their own handle (to the same key), which will be open and closed.

Has the user already logged in when each corresponding close function (RegCloseKey and UnloadUserProfile) is called?

Also.

+1
source

As I am currently trying to accomplish the same thing as me, I thought I would have something in common with what I found in the last few days.

I am running Windows XP sp3 and trying to impersonate using the CurrentUser registry registry in two different scenarios

If you meet anything useful, I would be very grateful if you share your experience. My stack overflow question can be found here

Admin> Restricted User and Restricted User> Admin

What I noticed so far (in Windows XP sp3)

LoadUserProfile ():

It only works when the impersonating user has SeRestoreName and SeBackupName privileges among others (just including these two for the limited user was not enough, as it still failed with an access denied error - see my question in StackOverflow for more details about it). The only way I can successfully call LoadUserProfile() is to do this with an administrator account before starting the impersonation.

RegOpenCurrentUser ():

It only works “correctly” when the user profile is already loaded. In every attempt I have made so far, I can only get the hive descriptor S-1-5-18 if the user hive is not loaded and accessible under HKEY_USERS already

+1
source

Two functions are used in different situations.

LoadUserProfile is suitable if the user profile has not yet been 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 online.

Note that LoadUserProfile usually called without impersonation (because you must have administrator privileges to use it), but RegOpenCurrentUser must be called with impersonation.

0
source

All Articles