Jeroen Mostert
7/9/2008 12:37:00 AM
Bruce Sanderson wrote:
> How does one cause a registry hive to be loaded or unloaded from/to a
> file - essentially, what is the .net framework equivalent of the
> RegLoadKey and RegUnLoadKey Functions in the Windows API?
>
There is none. This functionality is not exposed in the framework. You'll
have to P/Invoke (opening and modifying the key once the hive is loaded can
be done from .NET) or just do it in unmanaged code.
> I need to build a small application that will load the hive from
> %systemdriver$\Documents and Settings\Default User\ntuser.dat (Windows
> XP), set a particular value, then unload the hive. This is so any user
> that has not logged on before will get this registry value when their
> user specific profile (and ntuser.dat) file is created.
>
..NET typically handles this through cascading configuration files; a managed
application should not require a particular registry value to be present
somewhere. Even if you need to use the registry, an application could check
whether its expected value is missing for the user it's running under, and
if so, copy the default over from a subkey in HKEY_LOCAL_MACHINE.
If you can't modify the application logic and it depends on the value being
present before running, modifying the template user hive would be
acceptable. This is something you probably want to do from the setup
program, since it requires administrative privileges and only needs to
happen once. You typically wouldn't use a managed application for setup,
since the framework has its own prerequisites.
--
J.