Board index » delphi » TRegistry.SaveKey fails

TRegistry.SaveKey fails

hi there,

i have a problem writing a hive-file with TRegistry.SaveKey.
The file is created but its empty and the function returns false.

After writing the hive i can restore the data with RestoreKey, right?
What about this LoadKey? and why do i have to set the Root-Key
to something else than HKEY_CURRENT_USER?

I tried to use one machine in network to save all the configuration for
my program but it does not work. is there any example code to find out
more about this stuff?

thanks,

bye od

 

Re:TRegistry.SaveKey fails


Quote
In article <395B81F6.9F73D...@gmx.de>, Oliver Dawid wrote:
> i have a problem writing a hive-file with TRegistry.SaveKey.
> The file is created but its empty and the function returns false.

Have a look at MSDN Article Q128731 HOWTO: How to Back Up the Windows NT
Registry.  It explains various things that aren't obvious.  In particular
you need to enable the SeBackupPrivilege (it's disabled by default, even
if your user account has the 'Backup Files And Directories' right).

Also, you need access to the key to call SaveKey using the TRegistry
class.  NT provides a workaround, so that you can backup keys even if you
don't have access to them (using the REG_OPTION_BACKUP_RESTORE option)
and the Delphi TRegistry class can't do that.

Quote
> After writing the hive i can restore the data with RestoreKey, right?

Yes.  It restores an area of the registry saved with 'SaveKey'

Quote
> What about this LoadKey? and why do i have to set the Root-Key
> to something else than HKEY_CURRENT_USER?

Basically LoadKey (and the underlying RegLoadKey API) can only load keys
into a sub-key which it creates off a static registry root key.  And
there are only two static registry root keys - HKEY_LOCAL_MACHINE and
HKEY_USERS.  The other 'root' keys are aliases:
HKEY_CURRENT_CONFIG is an alias for
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Hardware Profiles\Current

HKEY_CURRENT_USER is an alias for HKEY_USERS\<S- .. .. >

HKEY_CLASSES_ROOT is an alias for HKEY_LOCAL_MACHINE\Software\Classes

Have a look at the help for the RegLoadKey API function.  It explains the
restrictions there.

I think though, that you shouldn't be using hives for this.  They've got
specific and fairly limited functionality.  

To do it the quick-and-dirty way, simply open the key on the remote
computer and copy the values you want across one by one.

To do it properly, maybe create a new class - based on TRegistry - but
with new methods that allow you to export or import a registry area -
maybe from 'regedit' compatible .REG files.

Colin
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm

Other Threads