views:

859

answers:

1

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

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.

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

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.

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?

What are the implications and differences (if any) between what happens 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?

+1  A: 

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.

Steve M