Good morning Bruce and Jeroen,
Apart from Jeroen's great suggestions, I'd like to give some .NET sample
code for RegLoadKey and RegUnLoadKey so that it's easier to come by.
According to the MSDN article
http://msdn.microsoft.com/en-us/library/ms724889(VS.85).aspx, the calling
process of RegLoadKey must have the SE_RESTORE_NAME and SE_BACKUP_NAME
privileges on the computer in which the registry resides. Therefore, a
simple P/Invoke of RegLoadKey may still not work for lack of the proper
privileges, and an 1314 error (A required privilege is not held by the
client) will be returned even if you are an administrator of the computer
(Being an admin account doesn't necessarily mean that you have those
privileges).
There is a KB article that demonstrates how to set the privilege and load &
unload a user profile:
http://support.microsoft.com/kb/297060
However, its example code is in VB6.
The .NET sample code can be found at:
http://www.csharphelp.com/archives2/archive430.html
(see the code at the bottom of the page)
I have tested it, and it worked well in my Windows XP, and 2003 boxes.
If you are using Windows Vista, an additional manifest that forces the
application to run as Administrator will be necessary:
http://community.bartdesmet.net/blogs/bart/archive/2006/10/28/Windows-Vista-
_2D00_-Demand-UAC-elevation-for-an-application-by-adding-a-manifest-using-mt
.exe.aspx
(this long URL may be truncated by the newsgroup system. Please concat it
manually, thanks)
Please let me know if you have any other concerns, or need anything else.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.