Solved

TRegistry.SaveKey

Posted on 2000-04-28
8
1,358 Views
Last Modified: 2008-03-17
Delphi 5, TRegistry.SaveKey
function SaveKey(const Key, FileName: String): Boolean; does not work anyway.
Someone knows the usage to make it work?
Regards
Wandrey
0
Comment
Question by:wandrey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Expert Comment

by:msedi
ID: 2758562
Hello,

I don't know what you did before and what functions you have used before. So I begin with the first step:

var
  Reg : TRegistry;

begin
  Reg := TRegistry.Create();
  Reg.RootKey := HKEY_LOCAL_MACHINE; <- Maybe that's what you forgot

Good luck,
Martin

 
0
 

Author Comment

by:wandrey
ID: 2758605
Ok, thats all simple beginning - I have wrote many tools with TRegistry, access local and remote hosts, read, write and change values - all of that was no problem. But the SaveKey does not function at all - not in the manner the online help suggests nor in any other imaginable possibility.
Background: I want to write a hole key with all of its subkeys and values to a diskfile for later campares to avoid the enumaration through the hole keys and values. The prog. must run on NT 4 SP6 in the admin security context (so there are no restrictions).
0
 
LVL 1

Expert Comment

by:msedi
ID: 2758628
Hello,

I've looked in the Borland community

http://community.borland.com/article/0,1410,10348,00.html

looks like there's an error in D5 TRegistry.

Good luck, Martin
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:wandrey
ID: 2758686
Hello,
thanks for all your efforts, I have search and found these and other articles also. But there seem to be some people out there, who has solve this problem, or might say dont have this problem.(i.e. in here:qid=10128124 is a question around this topic).
regards
Willy
0
 

Author Comment

by:wandrey
ID: 2758698
Concrete:
Called from Button1Click()->
>>>>>>>>>>>>>>>>>>>>>>>>
procedure TForm1.scanregpath;
var i:integer;
    sl:tstringlist;
begin
    cu := TRegistry.Create;
    cu.RootKey := HKEY_LOCAL_MACHINE;
  try
    if cu.savekey('\software\McAfee\VirusScan','c:\temp\rkey') then
      showmessage('Written...')
    else showmessage('Fail');
  finally
    cu.Free;
  end;
end;
<<<<<<<<<<<<<<<<<<<<<<<<<<<<
This returns "Fail". The file in C:\TEMP was created but empty.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2758888
Hi,
i just tested this and it seems to work ok ,see how it goes for you :

implementation

{$R *.DFM}
uses registry;

procedure TForm1.Button1Click(Sender: TObject);
var
 reg : tregistry;
begin
 Reg := TRegistry.Create;
 Reg.RootKey:=HKEY_LOCAL_MACHINE;  {OR HKEY_USERS }
  if not fileexists('c:\myreg.reg') then
   try
     if Reg.SaveKey('\Software\Borland\Delphi', 'c:\myreg.reg') then
        ShowMessage( 'Saved' )
      else
        ShowMessage( 'Error Saving' )
        finally
      Reg.Free;
    end
  else showmessage('File already exists');
 end;

Regards Barry
0
 
LVL 3

Accepted Solution

by:
shenqw earned 25 total points
ID: 2758966
//Win98 is ok.
//On NT you must have backup Privileges

procedure TForm1.Button1Click(Sender: TObject);
const
  ADJUST_PRIV = TOKEN_QUERY or TOKEN_ADJUST_PRIVILEGES;
  SHTDWN_PRIV = 'SeBackupPrivilege';
  PRIV_SIZE   = sizeOf(TTokenPrivileges);
var
  cu:TRegistry;
  TokenPriv, Dummy: TTokenPrivileges;
  Token: THandle;
  Len:DWORD;
begin
    cu := TRegistry.Create;
    cu.RootKey := HKEY_LOCAL_MACHINE;
    DeleteFile('c:\temp\rkey');
    OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, Token);
    LookupPrivilegeValue(nil, SHTDWN_PRIV,TokenPriv.Privileges[0].Luid);
    TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    TokenPriv.PrivilegeCount := 1;  // One privilege to set
    AdjustTokenPrivileges(Token, false, TokenPriv, PRIV_SIZE,Dummy, Len);
    try
      if cu.savekey('\Software\NuMega','c:\temp\rkey') then
        showmessage('Written...')
      else showmessage('Fail');
    finally
      cu.Free;
    end;
end;
0
 

Author Comment

by:wandrey
ID: 2768192
Thanks, this was very good!
Regards
Willy
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 106
Firemonkey allowing RTL on android 6 77
Delphi Firemonkey send email on Android 1 81
IP without any Dots 1 99
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question