Board index » delphi » How does TRegistry.SaveKey work?

How does TRegistry.SaveKey work?

Here is my problem: when executed, the following code produces two
empty files under NT and no files at all under 95.

registry := TRegistry.Create;
registry.RootKey := HKEY_CURRENT_USER;
Result := registry.SaveKey( '\Software\AppName', AppNameUserCfg );
registry.RootKey := HKEY_LOCAL_MACHINE;
Result := registry.SaveKey( 'SOFTWARE\AppName', AppNameComputerCfg );
registry.Free;

In both case, the functions return FALSE. Am I doing something wrong
here?

Thanks for any help,

Cheers,

Olivier

 

Re:How does TRegistry.SaveKey work?


Try using the WriteString method.

i.e.
  registry.WriteString('\Software\AppName', AppNameUserCfg');

Is the Key already there??  If not you will need to open the key as
well.  If you pass a True parameter during the Open, it will create the
key if it isn't there already.

Also, note the OpenKey function delivered uses KEY_ALL_ACCESS for
permissions on NT, and this can cause a problem if the user is not a
local admin on the box.

Jeff

Quote
Olivier Grosclaude wrote:
> Here is my problem: when executed, the following code produces two
> empty files under NT and no files at all under 95.

> registry := TRegistry.Create;
> registry.RootKey := HKEY_CURRENT_USER;
> Result := registry.SaveKey( '\Software\AppName', AppNameUserCfg );
> registry.RootKey := HKEY_LOCAL_MACHINE;
> Result := registry.SaveKey( 'SOFTWARE\AppName', AppNameComputerCfg );
> registry.Free;

> In both case, the functions return FALSE. Am I doing something wrong
> here?

> Thanks for any help,

> Cheers,

> Olivier

Re:How does TRegistry.SaveKey work?


Try using the WriteString method.

i.e.
  registry.WriteString('\Software\AppName', AppNameUserCfg');

Is the Key already there??  If not you will need to open the key as
well.  If you pass a True parameter during the Open, it will create the
key if it isn't there already.

Also, note the OpenKey function delivered uses KEY_ALL_ACCESS for
permissions on NT, and this can cause a problem if the user is not a
local admin on the box.

Jeff

Quote
Olivier Grosclaude wrote:
> Here is my problem: when executed, the following code produces two
> empty files under NT and no files at all under 95.

> registry := TRegistry.Create;
> registry.RootKey := HKEY_CURRENT_USER;
> Result := registry.SaveKey( '\Software\AppName', AppNameUserCfg );
> registry.RootKey := HKEY_LOCAL_MACHINE;
> Result := registry.SaveKey( 'SOFTWARE\AppName', AppNameComputerCfg );
> registry.Free;

> In both case, the functions return FALSE. Am I doing something wrong
> here?

> Thanks for any help,

> Cheers,

> Olivier

Other Threads