Accessing the Registry Hive of Another User

From: D. Sami (anonymous_at_discussions.microsoft.com)
Date: 02/28/04


Date: Fri, 27 Feb 2004 21:16:05 -0800

I want to access/modify the registry hive of another user from an Administrator's account, I know the username and password of this user
I've searched msdn and I found that I can use LogonUser() then ImpersonateLoggedOnUser() then RegOpenCurrentUser(), I did and everything went fine
but On calling RegOpenCurrentUser(), I Get ERROR_ACCESS_DENIED, How can I solve this?

Here's the code :

HANDLE token; // the logged on user token.
BOOL b;

b = LogonUser("Test", ".", "test", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &token);
b = ImpersonateLoggedOnUser(token);

HKEY baseKey;
HKEY subKey;

LONG l = RegOpenCurrentUser(KEY_ALL_ACCESS, &baseKey); // ERROR_ACCESS_DENIED.

thanks much