HOWTO: Use RegOpenCurrentUser to Map to the User for the Currently Loaded Hive

ID: Q229675

This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about obtaining support for a Beta release, please see the documentation included with the Beta product files, or check the Web location from which you downloaded the release.
The information in this article applies to:


SUMMARY

You can access registry values for multiple users in your application by loading each user's hive programmatically. Use the RegOpenCurrentUser API function to retrieve a handle to the HKEY_CURRENT_USER key for the user that the current thread is impersonating.


MORE INFORMATION

HKEY_CURRENT_USER maps to the root of the current user's hive. The value of HKEY_CURRENT_USER does not change with the security context when another user's hive is loaded. In previous versions of Windows there was no safe way to access registry values for another user. You had to use RegCloseKey() and RegOpenKeyEx to remap HKEY_CURRENT_USER to the desired user's hive.

The RegOpenCurrentUser API function is new to Windows 2000, and provides a safe way to retrieve registry information about the user that the current thread is impersonating. RegOpenCurrentUser opens the key representing your thread's token, or Default if the profile isn't loaded.


REFERENCES

For additional information about loading another user's hive, please see the following article(s) in the Microsoft Knowledge Base:

Q168877 HOWTO: Load a User's Hive Programmatically
Q199190 Reference Another User's Hive Through HKEY_CURRENT_USER


Also, see the RegOpenCurrentUser topic in the Platform SDK Documentation.

Additional query words: compatguidestability


Keywords          : kbWinOS2000 kbSDKWin32 kbGrpKernBase 
Version           : winnt:
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: May 25, 1999